SW ExpertAcademy/D2

1926. 간단한 369게임

Programmer. 2018. 12. 1. 16:11

1926. 간단한 369게임

문제출처: https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5PTeo6AHUDFAUq&categoryId=AV5PTeo6AHUDFAUq&categoryType=CODE




풀이 방법



<코드>


#include <iostream>

int check369(int number)
{
	int retval{ 0 };
	int value = number;

	while (value != 0)
	{
		int test = value % 10;
		if (test == 3 || test == 6 || test == 9)
			retval++;
		value /= 10;
	}
	return retval;
}

int main(int argc, char** argv)
{
	std::ios::sync_with_stdio(false);
	std::cout.tie(nullptr);
	std::cin.tie(nullptr);

	int nValue{};
	std::cin >> nValue;

	for (int i = 1; i <= nValue; i++)
	{
		int count{};
		if ((count = check369(i)) > 0)
			for (int j = 0; j < count; j++)
				std::cout << "-";
		else
			std::cout << i;
		std::cout << " ";
	}
	std::cout << "\n";

	return 0;
}