1、第二届软件大赛答案第一道大题 下列乘法算式中:每个汉字代表1个数字(19)。相同的汉字代表相同的数字,不同的汉字代表不同的数字。 第 2/2 页 赛软件 * 比赛 = 软件比拼 试编程确定使得整个算式成立的数字组合。#include stdio.h#include stdlib.hbool unequal(int a1,int a2,int a3,int b1) int a4; a0=a1; a1=a2; a2=a3; a3=b1; int i,j; for(i=0;i4;i+) for(j=i+1;j4;j+) if(aj=ai) return false; return true;bool
2、 cal(int a,int b) int a1,a2,a3,b1,b2; a1=a/100; a2=(a-a1*100)/10; a3=a%10; b1=b/10; b2=b%10; if(a1=b2) & unequal(a1,a2,a3,b1) return true; return false;bool dif(int c4,int a1,int a2,int a3,int b1) int a4; a0=a1; a1=a2; a2=a3; a3=b1; for(int i=0;i4;i+) if(c4=ai)return false; return true; bool cal1(in
3、t a,int b,int c) int a1,a2,a3,b1,b2,c1,c2,c3,c4; a1=a/100; a2=(a-a1*100)/10; a3=a%10; b1=b/10; b2=b%10; c1=c/1000; c2=(c-c1*1000)/100; c3=(c-c1*1000-c2*100)/10; c4=c%10; if(c1=a2) & (c2=a3) & (c3=b1) & dif(c4,a1,a2,a3,b1) return true; return false; int main() int FirstNum,SecondNum,Result; for(First
4、Num=111;FirstNum=999;FirstNum+) for(SecondNum=11;SecondNum=1111 & Result, , , , , , , ,= ;int LocateVex(char a) for(int i=0;i=0 & c=9) return true; return false; char Precede(char a,char c) int i=LocateVex(a); int j=LocateVex(c); return tableij;int cal(int a,char op,int b) if(b=0 & op=/)flag=1;retur
5、n -1; switch(op) case +:return a+b;break; case -:return a-b;break; case *:return a*b;break; case /:return a/b;break; default:break; void func(char Mstr80) char str80; int len; char op; int num1; int num2; int result; int i,j,k; char c; /printf(n 请输入要求值的表达式 n); /gets(str); strcpy(str,Mstr); DisposeSt
6、r(str); len=strlen(str); /printf(%d,len); InitOpndStack(); InitOptrStack(); PushOptrStack(#); i=0; c=stri+; while(c!=# | GetTopOptr()!=#) if(isOpnd(c)PushOpndStack(c-0);c=stri+; else switch(Precede(GetTopOptr(),c) case : op=PopOptrStack(); num2=PopOpndStack(); num1=PopOpndStack(); result=cal(num1,op
7、,num2); if(flag=0) PushOpndStack(result); break; default:break; if(flag=1)break; if(flag=1) flag=0;return; else int total=GetTopOpnd(); if(total=24) printf(n %s 结果是 %dn,Mstr,total); char converse(int i) switch(i-1) case 0:return +;break; case 1:return -;break; case 2:return *;break; case 3:return /;
8、break; default:break; int main() char temp80; int i=0; int digit4; int op3; int k; for(digit0=1;digit0=9;digit0+) for(digit1=1;digit1=9;digit1+) for(digit2=1;digit2=9;digit2+) for(digit3=1;digit3=9;digit3+) for(op0=1;op0=4;op0+) for(op1=1;op1=4;op1+) for(op2=1;op2=4;op2+) for(k=0;k10;k+) if(k=0) tem
9、p0=digit0+0; temp1=converse(op0); temp2=digit1+0; temp3=converse(op1); temp4=digit2+0; temp5=converse(op2); temp6=digit3+0; temp7=0; func(temp); else if(k=1) temp0=(; temp1=digit0+0; temp2=converse(op0); temp3=digit1+0; temp4=); temp5=converse(op1); temp6=digit2+0; temp7=converse(op2); temp8=digit3+
10、0; temp9=0; func(temp); else if(k=2) temp0=digit0+0; temp1=converse(op0); temp2=(; temp3=digit1+0; temp4=converse(op1); temp5=digit2+0; temp6=); temp7=converse(op2); temp8=digit3+0; temp9=0; func(temp); else if(k=3) temp0=digit0+0; temp1=converse(op0); temp2=digit1+0; temp3=converse(op1); temp4=(; t
11、emp5=digit2+0; temp6=converse(op2); temp7=digit3+0; temp8=); temp9=0; func(temp); else if(k=4) temp0=(; temp1=digit0+0; temp2=converse(op0); temp3=digit1+0; temp4=converse(op1); temp5=digit2+0; temp6=); temp7=converse(op2); temp8=digit3+0; temp9=0; func(temp); else if(k=5) temp0=digit0+0; temp1=conv
12、erse(op0); temp2=(; temp3=digit1+0; temp4=converse(op1); temp5=digit2+0; temp6=converse(op2); temp7=digit3+0; temp8=); temp9=0; func(temp); else if(k=6) temp0=(; temp1=(; temp2=digit0+0; temp3=converse(op0); temp4=digit1+0; temp5=); temp6=converse(op1); temp7=digit2+0; temp8=); temp9=converse(op2);
13、temp10=digit3+0; temp11=0; func(temp); else if(k=7) temp0=(; temp1=digit0+0; temp2=converse(op0); temp3=(; temp4=digit1+0; temp5=converse(op1); temp6=digit2+0; temp7=); temp8=); temp9=converse(op2); temp10=digit3+0; temp11=0; func(temp); else if(k=8) temp0=digit0+0; temp1=converse(op0); temp2=(; tem
14、p3=(; temp4=digit1+0; temp5=converse(op1); temp6=digit2+0; temp7=); temp8=converse(op2); temp9=digit3+0; temp10=); temp11=0; func(temp); else if(k=9) temp0=digit0+0; temp1=converse(op0); temp2=(; temp3=digit1+0; temp4=converse(op1); temp5=(; temp6=digit2+0; temp7=converse(op2); temp8=digit3+0; temp9=); temp10=); temp11=0; func(temp); else system(pause); return 0;
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2