这是老师给的第一道题目,并把它作出来了!!值得留念。 /* C R O S S +R O A D S ----------- D A N G E R 求上式子种各个字母代表的数字。 经过再三思考,D必为1,R必为偶数且2S=R或2S=R+10,C!=0,R!=0。这样可以减少循环次数。 */ #include <stdio.h> void main() { int c,r,o,s; int a,d; int n,g,e; int one,two,temp,sum; d=1; for(s=0;s<=9;s++) { if(s==d) continue; for(r=0;r<=8;r++) { if(r==s||r==d) continue; if(r==2*s||r+10==2*s) { for(c=2;c<=9;c++) { if(c==r||c==s||c==d) continue; for(o=0;o<=9;o++) { if(o==c||o==r||o==s||o==d) continue; for(a=0;a<=9;a++) { if(a==o||a==c||a==r||a==s||a==d) continue; for(n=0;n<=9;n++) { if(n==a||n==o||n==c||n==r||n==s||n==d) continue; for(g=0;g<=9;g++) { if(g==n||g==a||g==o||g==c||g==r||g==s||g==d) continue; for(e=0;e<=9;e++) { if(e==g||e==n||e==a||e==o||e==c||e==r||e==s||e==d) continue; { one=c*10000+r*1000+o*100+s*10+s; two=r*10000+o*1000+a*100+d*10+s; temp=one+two; sum=d*100000+a*10000+n*1000+g*100+e*10+r; if(temp==sum) { printf("CROSS + ROADS = DANGER/n"); printf("%d + %d = %d /n",one,two,sum); } } } } } } } } } } } }