Bibi's DevLog ๐Ÿค“๐ŸŽ

[๋ฐฑ์ค€ 5704] ํŒฌ๊ทธ๋žจ ๋ณธ๋ฌธ

ํ”„๋กœ๊ทธ๋ž˜๋ฐ/์•Œ๊ณ ๋ฆฌ์ฆ˜ ํ’€์ด Swift

[๋ฐฑ์ค€ 5704] ํŒฌ๊ทธ๋žจ

๋น„๋น„ bibi 2022. 11. 14. 11:04

[๋ฐฑ์ค€ 5704] ํŒฌ๊ทธ๋žจ

5704๋ฒˆ: ํŒฌ๊ทธ๋žจ

์ž…๋ ฅ๋œ ๋ฌธ์žฅ์— ๋ชจ๋“  ์•ŒํŒŒ๋ฒณ์ด ๋“ค์–ด์žˆ๋Š”์ง€ ํ™•์ธํ•˜๋ฉด ๋œ๋‹ค.

ํ’€์ด

while true {
    var alphabet = "abcdefghijklmnopqrstuvwxyz".map { $0 }
    let input = readLine()!
    if input == "*" {
        break
    }
    for item in input {
        if item == " " {
            continue
        }
        if let index = alphabet.firstIndex(of: item) {
            alphabet.remove(at: index)

        } else {
            continue
        }
    }
    alphabet.isEmpty ? print("Y") : print("N")
}

์•ŒํŒŒ๋ฒณ ๋ฐฐ์—ด์—์„œ ๋ฌธ์žฅ์— ์žˆ๋Š” ๊ธ€์ž๋“ค์„ ํ•˜๋‚˜์”ฉ ๋นผ๊ณ , ๋งˆ์ง€๋ง‰์— ๋ฐฐ์—ด์ด ๋น„์–ด์žˆ์œผ๋ฉด Y๋ฅผ ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด N์„ ์ถœ๋ ฅํ•œ๋‹ค.

๋‹ค๋ฅธ ํ’€์ด

outerLoop: while true {
    var alphabet = "abcdefghijklmnopqrstuvwxyz".map { $0 }
    let input = readLine()!
    if input == "*" {
        break
    }
    for abc in alphabet {
        if !input.contains(abc) {
            print("N")
            continue outerLoop
        }
    }
    print("Y")
}
  • ํ…Œ์ŠคํŠธ์ผ€์ด์Šค ์ฑ„์ ํ–ˆ์„ ๋•Œ ๋‚ด ํ’€์ด๋ณด๋‹ค ์„ฑ๋Šฅ์ด ์กฐ๊ธˆ ๋” ๋Š๋ ธ๋‹ค (24ms)
  • ์ฝ”๋“œ๊ฐ€ ์ข€ ๋” ์ง๊ด€์ ์ธ ์ ์€ ์ข‹์€ ๊ฒƒ ๊ฐ™๋‹ค!