반응형

이 문제는 10808번과 유사하게
아스키코드를 활용해서 풀면 되는 문제다
#include <iostream>
#include <string>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int a,b,c;
cin >> a >> b >> c;
int arr[10] = {};
int i = a*b*c;
string j = to_string(i);
for(int tmp : j)
{
arr[tmp-48]++;
}
for(int tmp : arr)
{
cout << tmp << "\n";
}
return 0;
}
똑같이 배열의 원소값을 숫자의 등장횟수로 정하고
0의 아스키코드 값이 48인 점을 활용하면 된다
int형을 string형으로 바꾸기 위해 to_string함수를 사용했다
// Authored by : BaaaaaaaaaaarkingDog
// Co-authored by : OceanShape
// http://boj.kr/fefbce1d30c9442db611909c690df1a8
#include <bits/stdc++.h>
using namespace std;
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
int A, B, C;
cin >> A >> B >> C;
int t=A*B*C;
int d[10] = {};
// 계산 결과를 자릿수별로 확인하여 저장
while (t>0) {
d[t%10]++;
t/=10;
}
for (int i=0; i<10; ++i) cout << d[i] << '\n';
}
창의적인 다른 풀이가 있어서 소개해보려 한다
while문으로 몫이 0이 될때까지 반복하여
나머지 값은 무조건 0~9이기에
나머지 값과 배열 상 원소의 위치를 같게하여 카운팅하는 방식이다
반응형
'algorithm > 배열' 카테고리의 다른 글
| [algorithm] 백준 11328번 Strfry (0) | 2026.01.10 |
|---|---|
| [algorithm] 백준 13300번 방 배정 (0) | 2026.01.10 |
| [algorithm] 백준 1475번 방 번호 (0) | 2026.01.10 |
| [algorithm] 백준 10807번 개수 세기 (0) | 2026.01.10 |
| [algorithm] 백준 10808번 알파벳 개수 (0) | 2026.01.10 |
