www.acmicpc.net/problem/2577

 

2577번: 숫자의 개수

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

www.acmicpc.net

언어 : cpp

방법은 간단하다. 

곱하기 한 숫자를 /10해가면서 나머지만 비교연산하는 것이다.

자존감 살리기 쉬운문제 풀기,,^^,,

#include <iostream>
using namespace std;
int main()
{
	int a, b, c,q,comp;
	int cnt[10] = {0,};
	int total; 
	cin >> a;
	cin >> b;
	cin >> c;

	if (a < 100 || a > 1000 || b < 100 || b > 1000 || c < 100 || c > 1000)
	{
		cout << "input error" << endl;;
	}
	total = a * b *c;

	while (1)
	{
		q = total / 10;
		comp = total % 10;
		for (int i = 0; i < 10; i++)
		{
			if (i == comp)
			{
				cnt[i] += 1;
			}
		}

		total = q; 
		if (total == 0)
		{
			break;
		}

	}
	for (int i = 0; i < 10; i++)
	{
		cout << cnt[i] << endl;
	}

	cin >> a;

	return 0;

}

'Programming > 알고리즘' 카테고리의 다른 글

[프로그래머스] 타겟 넘버  (0) 2021.03.22
[프로그래머스] 크레인 인형뽑기 게임  (0) 2021.03.16
[백준][10174]팰린드롬  (0) 2020.10.17
백준 3190 뱀  (0) 2019.10.11
정렬 알고리즘 - 수정  (0) 2017.11.17
복사했습니다!