백준 2577 - 숫자의 개수

황재진·2024년 3월 7일

백준

목록 보기
17/54
post-thumbnail

숫자의 길이와 자릿수를 구할 수 있다면 해결할 수 있는 문제입니다.

#include <iostream>

int main()
{
	int a, b, c;

	int cnts[10];
	for (int i = 0; i < 10; i++)
		cnts[i] = 0;

	std::cin >> a >> b >> c;
	int n = a * b * c;

	int len = 0; // 숫자 길이
	int copy_n = n;
	while (copy_n > 0)
	{
		copy_n /= 10;
		len++;
	}

	int first_ten = 10;
	for (int i = 1; i < len; i++)
		first_ten *= 10;

	for (int i = 0; i < len; i++) // 자릿수 구하기
	{
		int temp = (n % first_ten / (first_ten / 10));
		first_ten /= 10;
		cnts[temp]++;
	}

	for (int i = 0; i < 10; i++)
		std::cout << cnts[i] << "\n";

	return 0;
}
profile
프로그래밍, 쉐이더 등 이것저것 다해보는 게임 개발자입니다

0개의 댓글