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

[๋ฐฑ์ค€ 2386] ๋„๋น„์˜ ์˜์–ด ๊ณต๋ถ€ ๋ณธ๋ฌธ

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

[๋ฐฑ์ค€ 2386] ๋„๋น„์˜ ์˜์–ด ๊ณต๋ถ€

๋น„๋น„ bibi 2022. 9. 7. 11:43

2386๋ฒˆ: ๋„๋น„์˜ ์˜์–ด ๊ณต๋ถ€

๊ทธ๋ƒฅ ์•ŒํŒŒ๋ฒณ์„ ๋Œ€์†Œ๋ฌธ์ž ๊ตฌ๋ถ„์—†์ด ์„ธ๋Š” ๋ฌธ์ œ์ธ๋ฐ, ์ž…๋ ฅ ํ˜•ํƒœ๊ฐ€ ์กฐ๊ธˆ ๋‹ฌ๋ผ์„œ ๊ทธ ๋ถ€๋ถ„์„ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฐ์—์„œ ์‹œ๊ฐ„์ด ์ข€ ๊ฑธ๋ ธ๋‹ค.

์ „์ฒด ์ž…๋ ฅ ์ค„์—์„œ ํ•ด๋‹น ์•ŒํŒŒ๋ฒณ ๊ฐฏ์ˆ˜๋ฅผ ์„ผ ๋‹ค์Œ, 1์„ ๋บ€ ๊ฐ’์„ ์ถœ๋ ฅํ–ˆ๋‹ค.

1์„ ๋บ€ ๊ฒƒ์€ ์ž…๋ ฅ ์ค„ ๋งจ ์•ž์— ์ œ์‹œ๋œ ์•ŒํŒŒ๋ฒณ 1๊ฐœ๋Š” ๋นผ์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ.

ํ’€์ด

while true {
    let input = readLine()!.lowercased()
    if input == "#" {
        break
    }
    let inputArr = input.split(separator: " ")
    let alphabet = inputArr[0]
    var alphabetCount = 0
    for inputChar in input {
        print(inputChar)
        if String(inputChar) == alphabet {
            alphabetCount += 1
        }
    }
    print("\(alphabet) \(alphabetCount - 1)")
}