만능재주꾼

[백준 2577] 숫자의 개수 - JAVA 본문

💻 Algorithm/BOJ

[백준 2577] 숫자의 개수 - JAVA

유고랭 2021. 1. 2. 16:38

문제

풀이

import java.io.*;
public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n1 = Integer.parseInt(br.readLine());
		int n2 = Integer.parseInt(br.readLine());
		int n3 = Integer.parseInt(br.readLine());
		
		String num = Integer.toString(n1*n2*n3);
		int arr[] = {0,0,0,0,0,0,0,0,0,0};
		
		for(int i=0;i<num.length();i++) {
			String n = Character.toString(num.charAt(i));
			switch(n) {
			   case "0": arr[0]++; break;
			   case "1": arr[1]++; break;
			   case "2": arr[2]++; break;
			   case "3": arr[3]++; break;
			   case "4": arr[4]++; break;
			   case "5": arr[5]++; break;
			   case "6": arr[6]++; break;
			   case "7": arr[7]++; break;
			   case "8": arr[8]++; break;
			   case "9": arr[9]++; break;
			}
		}
		for(int i=0;i<arr.length;i++) {
			System.out.println(arr[i]);
		}
	}
}
Comments