Baekjoonアルゴリズム | 2577番問題: 数字の個数
出典
https://www.acmicpc.net/problem/2577
問題
Baekjoon Online Judgeの2577番問題、数字の個数を解きます。
入力
正確な入力形式と制約は元の問題文に従います。
出力
問題で求められる答えを出力します。
サンプル入力 1
150 266 427
サンプル出力 1
3 1 0 2 0 0 0 2 0 0
アルゴリズム分類
- 数学
- 実装
解説
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
int a = Integer.parseInt(br.readLine());
int b = Integer.parseInt(br.readLine());
int c = Integer.parseInt(br.readLine());
String m = String.valueOf(a * b * c);
int[] counts = int[10];
for (int i = 0; i < m.length(); i++) {
int num = Integer.parseInt(String.valueOf(m.charAt(i)));
counts[num]++;
}
for(int count : counts) {
System.out.println(count);
}
}
}
}