์ฃผ์ด์ง ์๊ตฌ์ฌํญ์ ๊ตฌํํ๋ฉด ๋๋ ๋ฌธ์
๋ฌธ์
https://www.acmicpc.net/problem/4659
๋ด๊ฐ ์์ฑํ ์ฝ๋
Swift
let vowel = Array("aeiou")
while let input = readLine() {
if input == "end" {
break
}
var isAcceptable = true
// ๋ชจ์ ํ๋๋ฅผ ๋ฐ๋์ ํฌํจ
if !input.contains(where: ) {
isAcceptable = false
}
// ๋ชจ์์ด 3๊ฐ ํน์ ์์์ด 3๊ฐ ์ฐ์์ผ๋ก ์ค๋ฉด ์ ๋๋ค.
var arr = Array(input)
var isVowel = vowel.contains(input.first!)
var prevChar = input.first!
var count = 0
var max = arr.count
for i in 1..<max {
if isVowel && vowel.contains(arr[i]) { // ์ด์ ๋ฌธ์๊ฐ ๋ชจ์์ด๋ฉด์, ํ์ฌ ๋ฌธ์๋ ๋ชจ์์ธ ๊ฒฝ์ฐ
count += 1
} else if !isVowel && !vowel.contains(arr[i]) { // ์ด์ ๋ฌธ์๊ฐ ์์์ด๋ฉด์, ํ์ฌ ๋ฌธ์๋ ๋ชจ์์ธ ๊ฒฝ์ฐ
count += 1
} else {
isVowel = !isVowel
count = 0
}
// ๊ฐ์ ๊ธ์๊ฐ ์ฐ์์ ์ผ๋ก ๋๋ฒ ์ค๋ฉด ์๋จ. ee์ oo๋ ํ์ฉ
if prevChar == arr[i] && prevChar != "e" && prevChar != "o" {
isAcceptable = false
}
prevChar = arr[i]
if count >= 2 {
isAcceptable = false
}
}
if isAcceptable {
print("<\(input)> is acceptable.")
} else {
print("<\(input)> is not acceptable.")
}
}