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

Algorithm/Baekjoon

[๋ฐฑ์ค€] (Swift) 10808๋ฒˆ - ์•ŒํŒŒ๋ฒณ ๊ฐœ์ˆ˜

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

 

๋ฌธ์ œ ๋งํฌ

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

 

10808๋ฒˆ: ์•ŒํŒŒ๋ฒณ ๊ฐœ์ˆ˜

๋‹จ์–ด์— ํฌํ•จ๋˜์–ด ์žˆ๋Š” a์˜ ๊ฐœ์ˆ˜, b์˜ ๊ฐœ์ˆ˜, …, z์˜ ๊ฐœ์ˆ˜๋ฅผ ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„ํ•ด์„œ ์ถœ๋ ฅํ•œ๋‹ค.

www.acmicpc.net

 

 

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

0๋ฐฐ์—ด์„ ๋งŒ๋“ค์–ด์ฃผ๊ณ , ์ž…๋ ฅ๋ฐ›๋Š” ์•ŒํŒŒ๋ฒณ์„ ์•„์Šคํ‚ค์ฝ”๋“œ 10์ง„์ˆ˜๋กœ ๋ณ€ํ™˜ํ•œ๋’ค ํ•ด๋‹นํ•˜๋Š” ์ธ๋ฑ์Šค์œ„์น˜์˜ ์ˆ˜์— +1 ์”ฉ ํ•ด์ฃผ์—ˆ๋‹ค.

๊ธฐ์–ตํ•˜์ž, asciiValue ๋Œ€๋ฌธ์ž A๋Š” 65, ์†Œ๋ฌธ์ž a ๋Š” 97!! ์ƒ๊ฐ๋ณด๋‹ค ๋ฌธ์ž์—ด ํ•  ๋•Œ ์“ธ๋ชจ๊ฐ€ ์žˆ๋‹ค.

import Foundation

var array = [Int](repeating: 0, count: 26)
let line = readLine()!

for ch in line {
    array[Int(ch.asciiValue!)-97] += 1
}

print(array.map{ "\($0)" }.joined(separator: " "))

 

๋ฐ˜์‘ํ˜•