用递归写了一个
#include "stdio.h"
#define TRUE
1
#define FALSE 0
typedef unsigned char boolean;
boolean Judge(unsigned int *p[10])
{
int c2,c3,c4,c5;
c2=(*p[4]+*p[6]*2)/10;
c3=(*p[3]+*p[5]*2+c2)/10;
c4=(*p[2]+*p[3]*2+c3)/10;
c5=(*p[1]+c4)/10;
if(0 != (*p[6]*2)%10)
return FALSE;
if(0 != (*p[5]*2+c2)%10)
return FALSE;
if(*p[9] != (*p[2]+*p[3]*2+c3)%10)
return FALSE;
if(*p[8] != (*p[1]+c4)%10)
return FALSE;
if(*p[7] != (*p[0]+c5))
return FALSE;
return TRUE;
}
void guess(unsigned int n,unsigned int *p[10])
{
unsigned int i,j,flag;
if(0 == n)
{
if(TRUE == Judge(p))
{
printf("**************************************\n");
printf("A\tB\tC\tD\tE\t\n");
printf("%d\t%d\t%d\t%d\t%d\n",*p[0],*p[1],*p[2],*p[3],*p[4]);
printf("F\tG\tX\tY\tZ\t\n");
printf("%d\t%d\t%d\t%d\t%d\n",*p[5],*p[6],*p[7],*p[8],*p[9]);
printf("**************************************\n");
}
}
else
{
for(i=0;i<10;i++)
{
flag=TRUE;
for(j=9;j>=n;j--)
{
if(i == *p[j])
{
flag = FALSE;
break;
}
}
if(FALSE == flag)
continue;
*p[n-1]=i;
guess(n-1,p);
}
}
}
int main()
{
unsigned int A,B,C,D,E,F,G,X,Y,Z;
unsigned int *p[10];
p[0]=&A;p[1]=&B;p[2]=&C;p[3]=&D;p[4]=&E;
p[5]=&F;p[6]=&G;p[7]=&X;p[8]=&Y;p[9]=&Z;
guess(10,p);
getch();
}