/* Solves the solutions to the
abcde - fghij = 45678 problem
where a-j are 10 different
digits 0-9.
** Chip Schweikarth
** T.C.Programs ** (c) 2001
** April 10, 2001 **/
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
int main()
{
long value1,value2,radix = 10;
int num = 0;
char chr[6],chr2[6],c1,c2,c3,
c4,c5,c6,c7,c8,c9,c0;
for (value1 = 10000; value1 < 100000;
value1++)
{
for (value2 = 10000; value2 < 100000;
value2++)
{
if (value2 - value1 == 45678)
{
itoa(value1,chr,radix);
itoa(value2,chr2,radix);
c1 = chr[0];
c2 = chr[1];
c3 = chr[2];
c4 = chr[3];
c5 = chr[4];
c6 = chr2[0];
c7 = chr2[1];
c8 = chr2[2];
c9 = chr2[3];
c0 = chr2[4];
if ((c1 == c2) || (c1 == c3)
|| (c1 == c4) || (c1 == c5)
|| (c1 == c6) || (c1 == c7)
|| (c1 == c8) || (c1 == c9)
|| (c1 == c0) || (c2 == c3)
|| (c2 == c4) || (c2 == c5)
|| (c2 == c6) || (c2 == c7)
|| (c2 == c8) || (c2 == c9)
|| (c2 == c0) || (c3 == c4)
|| (c3 == c5) || (c3 == c6)
|| (c3 == c7) || (c3 == c8)
|| (c3 == c9) || (c3 == c0)
|| (c4 == c5) || (c4 == c6)
|| (c4 == c7) || (c4 == c8)
|| (c4 == c9) || (c4 == c0)
|| (c5 == c6) || (c5 == c7)
|| (c5 == c8) || (c5 == c9)
|| (c5 == c0) || (c6 == c7)
|| (c6 == c8) || (c6 == c9)
|| (c6 == c0) || (c7 == c8)
|| (c7 == c9) || (c7 == c0)
|| (c8 == c9) || (c8 == c0)
|| (c9 == c0))
break;
num++;
cout << value2 << " - "
<< value1 << " = "
<< (value2 - value1)
<< ". " << num
<< " answers.\n";
}
}
}
getch();
return(0);
}