一道题

1-9,9个数字,组成三个三位数,第二个是第一个的二倍,第三个是第二个和第一个的和,编程实现求出这三个数字。

#include<iostream>
using namespace std;
int a[10] = {0};
bool judge(int x)
{
if(a[x%10]==1) return false;
else a[x%10]=1;
if(a[x/100]==1) return false;
else a[x/100]=1;
if(a[x/10%10]==1) return false;
else a[x/10%10]=1;
return true;
}

int main()
{
int i=0,j=0;
for (i =100;i<333;i++)
{
cout<<"*******"<<i<<endl;

j = 0;
while(j<10)
{
a[j++] = 0;
}

if (judge(i)&&judge(2*i)&&judge(3*i))
{
cout<<i<<endl;
cout<<2*i<<endl;
cout<<3*i<<endl;
break;
}
}
return 0;
}

posted @ 2012-10-12 16:53  10,000 hours coder  阅读(177)  评论(0编辑  收藏  举报