알고리즘

C++ 알고리즘 - 백준 2577 숫자의 개수

마루설아 2024. 12. 14. 21:40

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

 

#include <iostream>
#include <string>
using namespace std;

int main(void) {
	// C++ Init
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	int in1, in2, in3;
	int gop;
	int chk[10] = { 0 };

	cin >> in1 >> in2 >> in3;

	gop = in1 * in2 * in3;

	string str = to_string(gop);
	int leng = str.length();


	for (int i = 0; i < leng; i++) {
		chk[str[i] - '0']++;
	}

	for (int i = 0; i < 10; i++) {
		cout << chk[i] << "\n";
	}
}

 

 

문자열과 정수를 서로 변환할 수 있어야 한다.