-
[Swift] ๋ฐฑ์ค 4659 ๋น๋ฐ๋ฒํธ ๋ฐ์ํ๊ธฐ (String)๐ป Algorithm/Swift 2023. 1. 31. 22:33
๐ ํ์ด
๐ฌ Code
import Foundation while (true) { let pw = readLine()! if pw == "end" { break } if pw.isPassedConditionA() && pw.isPassedConditionB() && pw.isPassedConditionC() { print("<\(pw)> is acceptable.") } else { print("<\(pw)> is not acceptable.") } } extension String { func isPassedConditionA() -> Bool { for alpha in self.map({ String($0) }) { if ["a", "e", "i", "o", "u"].contains(alpha) { return true } } return false } func isPassedConditionB() -> Bool { let arr = self.map{ String($0) } if arr.count > 2 { for i in 0..<arr.count-2 { let cnt = arr[i...i+2].filter{ ["a", "e", "i", "o", "u"].contains($0) }.count if cnt == 0 || cnt == 3 { return false } } } return true } func isPassedConditionC() -> Bool { var arr1 = self.dropLast().map { String($0) } var arr2 = self.dropFirst().map { String($0) } for (a, b) in zip(arr1, arr2) { if (a == b) && !(a == "e" || a == "o") { return false } } return true } }
'๐ป Algorithm > Swift' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Swift] ๋ฐฑ์ค 1260 DFS์ BFS (Graph Traversal) (0) 2023.01.31 [Swift] ๋ฐฑ์ค 14490 ๋ฐฑ๋์ด (์ต๋๊ณต์ฝ์ GCM ๋ฌธ์ ) (0) 2023.01.31 [Swift] ๋ฐฑ์ค 2941 ํฌ๋ก์ํฐ์ ์ํ๋ฒณ (String) (0) 2023.01.31 [Swift] ๋ฐฑ์ค 1427 ์ํธ์ธ์ฌ์ด๋ (String) (0) 2023.01.31 [Swift] ๋ฐฑ์ค 1181 ๋จ์ด ์ ๋ ฌ (String) (0) 2023.01.31