[문제]
2577번: 숫자의 개수
첫째 줄에 A, 둘째 줄에 B, 셋째 줄에 C가 주어진다. A, B, C는 모두 100보다 크거나 같고, 1,000보다 작은 자연수이다.
www.acmicpc.net
[코드]
import java.util.*
import java.io.*
fun main() {
val br = BufferedReader(InputStreamReader(System.`in`))
val bw = BufferedWriter(OutputStreamWriter(System.out))
val a = br.readLine().toInt()
val b = br.readLine().toInt()
val c = br.readLine().toInt()
var result = a*b*c
val arr = Array(10) { 0 }
while(result > 0){
arr[result%10] += 1
result /= 10
}
// "$result".forEach {
// arr[it.toInt()]
// }
arr.forEach {
bw.write("$it\n")
}
bw.flush()
bw.close()
}
[풀이]
배열 문제 중 기본에 해당하는 문제.
세 수를 곱한 수의 각 자리수에 해당하는 숫자의 0~9까지 각 수를 구한다.
배열 문제에서 중요한건 인덱스를 활용하는 것이다.
각 자리 수를 인덱스로 하여 배열의 값을 증가시켜 출력하면 된다.
Github : https://github.com/eshc123/2021AlgorithmStudy/blob/main/src/main/PS/baekjoon/2577.kt
'Algorithm and PS > 백준(Kotlin)' 카테고리의 다른 글
| 백준 - 13300 방 배정 (코틀린) (0) | 2021.05.15 |
|---|---|
| 백준 - 11328 Strfry (코틀린) (0) | 2021.05.15 |
| 백준 - 2309 일곱 난쟁이 (코틀린) (0) | 2021.05.10 |
| 백준 - 2562 최댓값 (코틀린) (0) | 2021.05.10 |
| 백준 - 10871 A+B (코틀린) (0) | 2021.05.07 |
댓글