Notice
Recent Posts
Recent Comments
Link
«   2025/02   »
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
Tags
more
Archives
Today
Total
관리 메뉴

main

[백준 - 2577번] 숫자의 개수 본문

Algorithm

[백준 - 2577번] 숫자의 개수

1984 2022. 1. 22. 16:11
  • 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