a b c d e
+2 0 0 8 5
------------
f g h i j
求abcdefghij分别表示从0到9的一位数字,而且不允许重复使得上面的加法表达式成立的所有组合
14982+20085=35067
27951+20085=48036
37941+20085=58026
41973+20085=62058
51963+20085=72048
64932+20085=85017
Press any key to continue
#include<iostream>
using namespace std;
int main(int argc, char* argv[])
{
int intar[10];
int intNumber, intResult;
bool bMatch;
for (intNumber = 10001; intNumber < 100000; intNumber++)
{
intar[0] = intNumber/10000;
intar[1] = (intNumber/1000)%10;
intar[2] = (intNumber/100)%10;
intar[3] = (intNumber/10)%10;
intar[4] = intNumber%10;
intResult = intNumber + 20085;
if (intResult >= 100000)
continue;
intar[5] = intResult/10000;
intar[6] = (intResult/1000)%10;
intar[7] = (intResult/100)%10;
intar[8] = (intResult/10)%10;
intar[9] = intResult%10;
bMatch = true;
for (int i = 0; i < 10 && bMatch; i++)
{
for (int j = 0; j < 10 && bMatch; j++)
{
if (i==j)
continue;
if (intar[i]==intar[j])
bMatch = false;
}
}
if (bMatch)
cout << intNumber << "+20085=" << intResult << endl;
}
return 0;
}