Potato
์•ˆ๋…•ํ•˜์„ธ์š”, ๊ฐ์žก๋‹ˆ๋‹ค?๐Ÿฅ” ^___^ ๐Ÿ˜บ github ๋ฐ”๋กœ๊ฐ€๊ธฐ ๐Ÿ‘‰๐Ÿป

Algorithm/Baekjoon

[๋ฐฑ์ค€] (Swift) 10820๋ฒˆ - ๋ฌธ์ž์—ด ๋ถ„์„

๊ฐ์ž ๐Ÿฅ” 2022. 2. 16. 16:05
๋ฐ˜์‘ํ˜•

 

๋ฌธ์ œ ๋งํฌ

https://www.acmicpc.net/problem/10820

 

10820๋ฒˆ: ๋ฌธ์ž์—ด ๋ถ„์„

๋ฌธ์ž์—ด N๊ฐœ๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ด๋•Œ, ๋ฌธ์ž์—ด์— ํฌํ•จ๋˜์–ด ์žˆ๋Š” ์†Œ๋ฌธ์ž, ๋Œ€๋ฌธ์ž, ์ˆซ์ž, ๊ณต๋ฐฑ์˜ ๊ฐœ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ๊ฐ ๋ฌธ์ž์—ด์€ ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž, ๋Œ€๋ฌธ์ž, ์ˆซ์ž, ๊ณต๋ฐฑ์œผ๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ

www.acmicpc.net

 

 

๋‚ด๊ฐ€ ํ‘ผ ํ’€์ด

  • ์ž…๋ ฅ๋ฐ›์€ character๋ฅผ ๋ชจ๋‘ ํ•œ ๋ฌธ์ž์”ฉ ๋œฏ์–ด์„œ ๋ฐฐ์—ด๋กœ ์ €์žฅํ•ด์ค€ ๋‹ค์Œ, if ๋ฌธ์„ ํ™œ์šฉํ•ด์„œ count
while let input = readLine() {
    
    var str = Array(input)
    var lower = 0
    var upper = 0
    var num = 0
    var space = 0
    
    for i in str {
        if i >= "a" && i <= "z" {
            lower += 1
        } else if i >= "A" && i <= "Z" {
            upper += 1
        } else if i == " " {
            space += 1
        } else {
            num += 1
        }
    }
    print("\(lower) \(upper) \(num) \(space)")
}
๋ฐ˜์‘ํ˜•