기술 블로그

2577번 숫자의 개수 본문

알고리즘 문제/BOJ

2577번 숫자의 개수

parkit 2018. 12. 25. 00:57
728x90
반응형

https://www.acmicpc.net/problem/2577


C++의 to_string()만 알면 쉽게 풀 수 있다.


to_stirng() : 숫자(정수형)를 문자열로 바꿔준다.


예) 

int num = 123;

string s = to_string(num);



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
#include <iostream>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <cstring>
#include <string>
#include <math.h>
#include <algorithm>
 
using namespace std;
 
int main(void)
{
    int A = 0, B = 0, C = 0;
 
    int num[10= { 0, };
 
    scanf("%d %d %d"&A, &B, &C);
 
    string s = to_string(A*B*C);
 
    for (int i = 0; i < s.length(); i++)
        ++num[s.at(i) - '0'];
 
    for (int i = 0; i <= 9; i++
        printf("%d\n", num[i]);
    
    return 0;
}
cs


728x90
반응형

'알고리즘 문제 > BOJ' 카테고리의 다른 글

1107번 리모컨  (0) 2018.12.26
11657번 타임머신  (0) 2018.12.26
5567번 결혼식  (0) 2018.12.24
9372번 상근이의 여행  (0) 2018.12.19
2231번 분해합  (0) 2018.12.18