자라는 개발자/문제풀이

백준 C++/C 2577번 숫자의 개수

자란다 2021. 12. 27. 23:46
728x90
반응형

2577번 숫자의 개수


문제 풀이

#include <iostream>
#include <string.h>
using namespace std;
void fast_io(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int main(void)
{
    fast_io();
    int a, b, c, i = 0;
    int num[10] = {
        0,
    };
    cin >> a >> b >> c;
    string str = to_string(a * b * c);
    for (char c : str)
    {
        num[c - '0']++;
    }
    for (int n : num)
    {
        cout << n << "\n";
    }
}

for(char c:str)을 사용하니까 이전에 시도하려던 것보다 비교적 깔끔하게 됐다.

728x90
반응형