자기개발👨‍💻/코딩 알고리즘

[python, C++] 백준 2577 숫자의 개수

천숭이 2022. 1. 30. 00:01

- python

a=int(input()); b=int(input()); c=int(input())
mul = str(a*b*c)
for i in range(10) :
    print(mul.count(str(i)))

 

- C++

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

int main() {
	int a, b, c;
	int mul = 0;
	string str;
	int count[10] = {};
	cin >> a >> b >> c;

	mul = a * b * c;

	string s = to_string(mul); // int to string
	
	// s 순회하며 해당 인덱스 값 +1
	for (char ch : s) {
		count[ch-'0']++;  // **아스키코드 0값 빼주기**
	}

	for (int i : count) {
		cout << i << endl;
	}
}