Baekjoon Algorithm | Problem 2577: Number of Digits

Source

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

Problem

Solve Baekjoon Online Judge problem 2577, Number of Digits.

Input

Follow the input format and constraints given in the original problem statement.

Output

Print the answer required by the problem.

Sample Input 1

150 266 427

Sample Output 1

3 1 0 2 0 0 0 2 0 0

Algorithm Classification

  • Math
  • Implementation

Solution

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);
            }
        }
    }
}