IT 일기장

[백준] 2577번 : 숫자의 개수 본문

백준

[백준] 2577번 : 숫자의 개수

뽕슈 2021. 12. 18. 21:57
반응형

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

 

2577번: 숫자의 개수

첫째 줄에 A, 둘째 줄에 B, 셋째 줄에 C가 주어진다. A, B, C는 모두 100보다 크거나 같고, 1,000보다 작은 자연수이다.

www.acmicpc.net

 

 

1. Scanner로도 할 수 있지만 BufferedReader로 선언했다.

2. 입력 3개 받고 곱해준다.

3. 0~9 까지 개수 받으려고 배열을 10개 선언했다. 그럼 딱 0~9 까지니까

4. 곱한 수를 10으로 계속 나눠주면서 10으로 나눈 나머지값을 배열에 담아준다.

 

ex) 11*22*33 = 7986

7986 % 10 = 6 (7986을 10으로 나눈 나머지)

798 % 10 = 8

79 % 10 = 9

7 % 10 = 7

 

5. 이렇게 배열에 담긴 값을 순차적으로 출력해준다

 

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int num = Integer.parseInt(br.readLine()) * Integer.parseInt(br.readLine()) * Integer.parseInt(br.readLine());
		int[] array = new int[10];

		while(num!=0) {
			array[num%10]++;
			num/=10;
		}

		for (int result : array) {
			System.out.println(result);
		}
	}
}
반응형

'백준' 카테고리의 다른 글

[백준] 1546번 : 평균  (0) 2021.12.27
[백준] 11720번 : 숫자의 합  (0) 2021.12.18
[백준] Arrays  (0) 2021.12.16
[백준] BufferedReader, BufferedWriter  (0) 2021.12.08
Comments