📄 subject_29707.htm
字号:
<br>内容:#include <stdio.h><BR>#include <stdlib.h><BR>#include <time.h><BR>//#include <math.h><BR><BR>/* 两个数的opration情况列举,并返回计算结束值 */<BR>int Run(int Opration,int A,int B);<BR><BR>/* 返回运算符 */<BR>char GetOpration(int s);<BR><BR>/*处理获得的随机数 */<BR>int DoWith(int p)<BR>{<BR> return p=p%10;<BR>}<BR><BR><BR>/* 把A的值和B的值交换一下 */<BR>void ExchangLcoation(int* pA,int* pB)<BR>{<BR>int Temp;<BR>Temp=*pA;<BR>*pA=*pB;<BR>*pB=Temp;<BR>}<BR><BR>/*调整数组中元素的个数*/<BR>void ChangDataLocation(int Count,int* pA,int* pB,int* pC,int* pD);<BR><BR><BR>int main()<BR>{<BR> <BR> int i=0,j=0,k=0,l=0;<BR> int a=0,b=0,c=0,d=0;<BR> int* p1=NULL;<BR> int* p2=NULL;<BR> int* p3=NULL;<BR> int* p4=NULL;<BR> <BR> int Result1=0;<BR> int Result21=0;<BR> int Result22=0;<BR> int Result31=0;<BR> int Result32=0;<BR> int Result33=0;<BR> int Result34=0;<BR> char IfContinue;<BR> printf("Welcome use it!\n");<BR> //printf("My dear freind, Are you ready?(Y/N)\n");<BR> //IfContinue=getchar();<BR> //if(IfContinue!='Y'||IfContinue!='y')<BR> //{<BR> // printf("Welcome use is again, bye!\n");<BR> // return;<BR> //}<BR> srand( (unsigned)time( NULL ) );<BR> a=DoWith(rand())+4;<BR> b=DoWith(rand())+2;<BR> c=DoWith(rand());<BR> d=DoWith(rand());<BR> <BR> <BR> //printf("Please input four digits:\n");<BR> //printf("Example: 12 24 12 1\n");<BR> //scanf("%d%d%d%d",&a,&b,&c,&d);<BR> printf("a=%d,b=%d,c=%d,d=%d\n",a,b,c,d);<BR> printf("Are you get it,Press any key get answer!\n");<BR> getchar();<BR> p1=&a;p2=&b;p3=&c;p4=&d;<BR> for(l=1;l<25;l++)<BR> {<BR> ChangDataLocation(l,p1,p2,p3,p4); /* 变换四个数字的位置 */<BR> for(i=1;i<5;i++)<BR> {<BR> Result1=Run(i,a,b);<BR> if(Result1==-1)<BR> continue;<BR> for(j=1;j<5;j++)<BR> {<BR> Result21=Run(j,Result1,c);<BR> /*if(Result21==-1)<BR> continue; */<BR> Result22=Run(j,c,Result1);<BR> <BR> for(k=1;k<5;k++)<BR> {<BR> Result31=Run(k,Result21,d);<BR> Result32=Run(k,d,Result21);<BR> Result33=Run(k,Result22,d);<BR> Result34=Run(k,d,Result22);<BR> if(Result31==24){ printf("((%d%c%d)%c%d)%c%d=24\n",a,GetOpration(i),b,GetOpration(j),c,GetOpration(k),d); return 0;}<BR> if(Result32==24){ printf("%d%c((%d%c%d)%c%d)=24\n",d,GetOpration(k),a,GetOpration(i),b,GetOpration(j),c); return 0;}<BR> if(Result33==24){ printf("(%d%c(%d%c%d))%c%d=24\n",c,GetOpration(j),a,GetOpration(i),b,GetOpration(k),d); return 0;}<BR> if(Result34==24){ printf("%d%c((%d%c%d(%c%d)=24\n",d,GetOpration(k),c,GetOpration(j),a,GetOpration(i),b); return 0;} <BR> }<BR> <BR> }<BR> }<BR> }<BR> printf("These four digits can't get 24 point!\n");<BR> return 0;<BR>}<BR><BR>/* 自定义函数 */<BR>/* 两个数的opration情况列举,并返回计算结束值 */<BR>int Run(int Opration,int A,int B)<BR>{<BR> if(Opration==1)<BR> return (A+B);<BR> if(Opration==2)<BR> {<BR> if( (A-B)<0 )<BR> return -1;<BR> return (A-B);<BR> }<BR><BR><BR><BR><BR><BR> if(Opration==3)<BR> return (A*B);<BR> if(Opration==4)<BR> {<BR> if(B==0)<BR> return -1;<BR> else<BR> if(A%B==0)<BR> return (A/B);<BR> else<BR> return -1;<BR> }<BR> <BR> return -1;<BR>}<BR><BR><BR>/* 返回运算符 */<BR>char GetOpration(int s)<BR>{<BR> if(s==1) return '+';<BR> if(s==2) return '-';<BR> if(s==3) return '*';<BR> if(s==4) return '/';<BR> return -1;<BR>}<BR><BR>/*自定义函数*/<BR>/*调整数组中元素的个数 */<BR>void ChangDataLocation(int Count,int* pA,int* pB,int* pC,int* pD)<BR>{<BR> if(Count>24||Count<1)<BR> {<BR> printf("The Count is wrong!\n");<BR> return;<BR> }<BR> <BR> /* 四个数的24种不同位置排列情况 */<BR> /* 01.A B C D 02.A B D C 03.A C B D 04.A C D B 05.A D B C 06.A D C B<BR> 07.B A C D 08.B A D C 09.B C A D 10.B C D A 11.B D A C 12.B D C A<BR> 13.C A B D 14.C A D B 15.C B A D 16.C B D A 17.C D A B 18.C d B A<BR> 19.D A B C 20.D A C B 21.D B A C 22.D B C A 23.D C A B 24.D C B A<BR> */<BR> /*参照上面,分别Count分别24种之一的编号*/<BR> if(Count==1) return;<BR> if(Count==2)<BR> { <BR> ExchangLcoation(pD,pC);<BR> return;<BR> }<BR> if(Count==3){ ExchangLcoation(pC,pB); return;}<BR> if(Count==4)<BR> {<BR> ExchangLcoation(pB,pD);<BR> ExchangLcoation(pC,pD);<BR> return;<BR> }<BR> if(Count==5)<BR> {<BR> ExchangLcoation(pB,pD);<BR> ExchangLcoation(pC,pD);<BR> return;<BR> }<BR> if(Count==6){ ExchangLcoation(pB,pD); return;}<BR> if(Count==7){ ExchangLcoation(pA,pB); return;}<BR> if(Count==8) <BR> {<BR> ExchangLcoation(pA,pB);<BR> ExchangLcoation(pC,pD);<BR> return;<BR> }<BR> if(Count==9)<BR> {<BR> ExchangLcoation(pA,pB);<BR> ExchangLcoation(pB,pC);<BR> return;<BR> }<BR> if(Count==10)<BR> {<BR> ExchangLcoation(pA,pB);<BR> ExchangLcoation(pC,pD);<BR> ExchangLcoation(pB,pD);<BR> return;<BR> }<BR> if(Count==11)<BR> {<BR> ExchangLcoation(pA,pB);<BR> ExchangLcoation(pC,pD);<BR> ExchangLcoation(pB,pC);<BR> return;<BR> }<BR> if(Count==12)<BR> {<BR> ExchangLcoation(pA,pB);<BR> ExchangLcoation(pB,pD);<BR> return;<BR> }<BR> if(Count==13)<BR> {<BR> ExchangLcoation(pA,pC);<BR> ExchangLcoation(pB,pC);<BR> return;<BR> }<BR> if(Count==14)<BR> {<BR> ExchangLcoation(pA,pC);<BR> ExchangLcoation(pB,pD);<BR> ExchangLcoation(pB,pC);<BR> return;<BR> }<BR> if(Count==15){ ExchangLcoation(pA,pC); return;}<BR> if(Count==16)<BR> {<BR> ExchangLcoation(pA,pC);<BR> ExchangLcoation(pC,pD);<BR> return;<BR> }<BR> if(Count==17)<BR> {<BR> ExchangLcoation(pA,pC);<BR> ExchangLcoation(pB,pD);<BR> return;<BR> }<BR> if(Count==18) <BR> {<BR> ExchangLcoation(pA,pC);<BR> ExchangLcoation(pB,pD);<BR> ExchangLcoation( pC, pD);<BR> return;<BR> }<BR> if(Count==19)<BR> {<BR> ExchangLcoation( pA, pD);<BR> ExchangLcoation( pB, pC);<BR> ExchangLcoation( pA, pC);<BR> return;<BR> }<BR> if(Count==20)<BR> {<BR> ExchangLcoation( pA, pD);<BR> ExchangLcoation( pB, pD);<BR> return;<BR> }<BR> if(Count==21)<BR> {<BR> ExchangLcoation( pA, pD);<BR> ExchangLcoation( pC, pD);<BR> return;<BR> }<BR> if(Count==22){ ExchangLcoation( pA, pD); return;}<BR> if(Count==23)<BR> {<BR> ExchangLcoation( pA, pD);<BR> ExchangLcoation( pB, pC);<BR> ExchangLcoation( pC, pD);<BR> return;<BR> }<BR> if(Count==24)<BR> {<BR> ExchangLcoation( pA, pD);<BR> ExchangLcoation( pB, pC);<BR> return;<BR> }<BR>}<BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:Justin Le 回复日期:2003-02-19 15:54:15
<br>内容:Welcome use it!<BR>a=9,b=2,c=5,d=7<BR>Are you get it,Press any key get answer!<BR><BR>((7*5)-2)-9=24
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -