题目(7)答案

其实都很简单,最重要的是3重循环不能超过内存限制
尽可能缩小时间复杂度

#include <iostream>
#include <string>

using namespace std;

bool check(int aNum1, int aNum2, int aNum3)
{
	bool search[15] = {false};
	/*aNum1 = (aNum1 * 1000 + aNum2) * 1000 + aNum3;
	string str;
	str = int2str(aNum1);
	192000->192384000->192384576*/
	while(aNum1 != 0)
	{
		search[aNum1 % 10] = true;
		aNum1 /= 10;
	}
	while(aNum2 != 0)
	{
		search[aNum2 % 10] = true;
		aNum2 /= 10;
	}
	while(aNum3 != 0)
	{
		search[aNum3 % 10] = true;
		aNum3 /= 10;
	}
	for(int i = 1; i <= 9; i++)
	{
		if(search[i] == true){
			continue;
		}
		else
			return false;
	}
	return true;
}

int main()
{
	/*
	192 384 576
	1~9 分成3组 每组3位数
	这3个数成1:2:3比例 
	*/
	bool c = false;
	for(int i = 100; i <= 333; i++)
	{
		for(int j = 200; j <= 666; j += 2)
		{
			for(int x = 300; x <= 999; x += 3)
			{
				c = check(i, j, x);
				if(c and i * 2 == j and i * 3 == x)
					cout << i << " " << j << " " << x << endl;
			}
		}
	}
	return 0;
}
posted @ 2020-01-16 15:51  Aeterna_Gungnir  阅读(115)  评论(0编辑  收藏  举报