main
[백준 - 2577번] 숫자의 개수 본문
- string foreach for
(char& c : str)
{
//code
}
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main(void)
{
int A, B, C;
int mul_three_num;
map<int, int> m;
cin >> A >> B >> C;
mul_three_num = A * B * C;
string str = to_string(mul_three_num);
for (int i = 0; i < 10; i++)
{
m.insert(make_pair(i, 0));
}
for (char& c : str)
{
// char to int " = '0'"
auto item = m.find(c - '0');
item->second++;
}
for (int i = 0; i < 10; i++)
{
cout << m[i] << '\n';
}
if (str.empty() != 0) {
}
return 0;
}
[참고 자료]
728x90
'Algorithm' 카테고리의 다른 글
[백준 - 1018번] 체스판 다시 칠하기 (0) | 2022.01.22 |
---|---|
[백준 - 2675번] 문자열 반복 (0) | 2022.01.22 |
[백준 - 2562번] 최댓값 (0) | 2022.01.22 |
[백준 - 1157번] 단어 공부 (0) | 2022.01.21 |
[백준 - 1152번] 단어의 개수 (0) | 2022.01.21 |
Comments