๊ธ€ ์ž‘์„ฑ์ž: ์ด์ง€์›๐ŸŒฉ๏ธ

์ฃผ์–ด์ง„ ์š”๊ตฌ์‚ฌํ•ญ์„ ๊ตฌํ˜„ํ•˜๋ฉด ๋˜๋Š” ๋ฌธ์ œ

 

๋ฌธ์ œ

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.")
    }
}
๋ฐ˜์‘ํ˜•