<문제>
세 개의 자연수 A, B, C가 주어질 때 A×B×C를 계산한 결과에 0부터 9까지 각각의 숫자가 몇 번씩 쓰였는지를 구하는 프로그램을 작성하시오.
예를 들어 A = 150, B = 266, C = 427 이라면
A × B × C = 150 × 266 × 427 = 17037300 이 되고,
계산한 결과 17037300 에는 0이 3번, 1이 1번, 3이 2번, 7이 2번 쓰였다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int tot = a*b*c;
int[] num = new int[10];
int n;
int i = 10;
while(tot/i!=0){
n = tot%i;
num[n]++;
tot = tot/i;
}
n = tot;
num[n]++;
for(int j=0; j<num.length; j++) {
System.out.println(num[j]);
}
}
}
|
'알고리즘 > 백준' 카테고리의 다른 글
[백준 1546번 ː 자바(JAVA)] 평균 (0) | 2020.04.27 |
---|---|
[백준 3052번 ː 자바(JAVA)] 나머지 (0) | 2020.04.27 |
[백준 2562번 ː 자바(JAVA)] 최댓값 (0) | 2020.04.24 |
[백준 10818번 ː 자바(JAVA)] 최소, 최대 (0) | 2020.04.22 |
[백준 2446번 ː 자바(JAVA)] 별 찍기 - 9 (0) | 2020.04.21 |