

풀이1
int를 문자열로 바꾸는것을 통해 아스키코드값을 이용하여 풀 수 있다.
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int a, b, c;
int cnt[10]={};
cin >> a >> b >> c;
int res = a * b * c;
/*
std::to_string(val)
숫자(int, long, float, double 등)를 문자열(string)으로
변환하여 반환해주는 함수를 사용한다.
*/
string s = to_string(res);
for( auto x : s){
cnt[x - '0']++;
}
for( auto y : cnt){
cout << y << '\n';
}
return 0;
}
풀이2
자연수에 % 10을 하면 나머지가 인덱스 역할이 되면서 어떤 숫자인지도 알 수 있다.
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int a, b, c;
cin >> a >> b >> c;
int res = a * b * c;
int cnt[10]={};
while(res > 0){
cnt[res % 10]++;
res /= 10;
}
for(auto x : cnt){
cout << x << '\n';
}
return 0;
}
'공부 일지 > 알고리즘' 카테고리의 다른 글
[바킹독 알고리즘]0x0A강 - DFS (0) | 2024.01.01 |
---|---|
[배열]BOJ 1475번 - 방 번호 (0) | 2023.12.30 |
[기초 코드 작성 요령 II]BOJ 15552번 - 빠른 A+B (0) | 2023.12.30 |
[기초 코드 작성 요령 II]BOJ 2557번 - Hello World (0) | 2023.12.30 |
[기초 코드 작성 요령 II]BOJ 1000번 - A+B (0) | 2023.12.30 |


풀이1
int를 문자열로 바꾸는것을 통해 아스키코드값을 이용하여 풀 수 있다.
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int a, b, c;
int cnt[10]={};
cin >> a >> b >> c;
int res = a * b * c;
/*
std::to_string(val)
숫자(int, long, float, double 등)를 문자열(string)으로
변환하여 반환해주는 함수를 사용한다.
*/
string s = to_string(res);
for( auto x : s){
cnt[x - '0']++;
}
for( auto y : cnt){
cout << y << '\n';
}
return 0;
}
풀이2
자연수에 % 10을 하면 나머지가 인덱스 역할이 되면서 어떤 숫자인지도 알 수 있다.
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int a, b, c;
cin >> a >> b >> c;
int res = a * b * c;
int cnt[10]={};
while(res > 0){
cnt[res % 10]++;
res /= 10;
}
for(auto x : cnt){
cout << x << '\n';
}
return 0;
}
'공부 일지 > 알고리즘' 카테고리의 다른 글
[바킹독 알고리즘]0x0A강 - DFS (0) | 2024.01.01 |
---|---|
[배열]BOJ 1475번 - 방 번호 (0) | 2023.12.30 |
[기초 코드 작성 요령 II]BOJ 15552번 - 빠른 A+B (0) | 2023.12.30 |
[기초 코드 작성 요령 II]BOJ 2557번 - Hello World (0) | 2023.12.30 |
[기초 코드 작성 요령 II]BOJ 1000번 - A+B (0) | 2023.12.30 |