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

 

2577번: 숫자의 개수

첫째 줄에 A, 둘째 줄에 B, 셋째 줄에 C가 주어진다. A, B, C는 모두 100보다 크거나 같고, 1,000보다 작은 자연수이다.

www.acmicpc.net

 

map STL을 이용해 숫자 개수를 체크해줬는데 너무 많은 라이브러리를 사용해 푼 것 같다.

다음번엔 배열만 사용해서 풀어보도록 하겠다.

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

int main(void) {
	int numCount;
	int nA;
	int nB;
	int nC;
    
	cin >> nA >> nB >> nC;
	numCount = nA * nB * nC;
	string sNum = to_string(numCount);
	map<int, int> mCount;
	for (auto it : sNum) {
		mCount[it] += 1;
	}

	for (int i = 48; i < 58; i++) {
		auto it = mCount.find(i);
		if (it == mCount.end()) {
			cout << 0 << endl;
		}
		else {
			cout << mCount[i] << endl;
		}
	}
    return 0;
}

 

+ Recent posts