Mentoring
[멘토링][c언어]백준 2577번 : 숫자의 개수
seomj
2020. 5. 18. 03:07
#include <stdio.h>
int main() {
int arr[10] = { 0, };
int a, b, c, total, rest;
scanf_s("%d", &a);
scanf_s("%d", &b);
scanf_s("%d", &c);
total = a * b * c;
while(total > 0) {
rest = total % 10;
total = total / 10;
arr[rest]++;
}
for (int i = 0; i < 10; i++) {
printf("%d \n", arr[i]);
}
return 0;
}
arr 배열의 모든 원소 값은 0으로 초기화 해두고 값을 하나씩 넣어줄 것이다. 먼저 a, b, c의 값을 입력받고 곱한 값을 total에 저장해준다. total 값에서 하나씩 rest에 저장하여 rest가 1이면 arr[1]에 +1이 된다. 그렇게 하나씩 값을 구해준다음에 for문을 사용하여 몇 개인지를 구해준다. arr[1]이 2라면 total에 1이 2개 들어있는 것이다.