您好,登錄后才能下訂單哦!
下邊代碼內(nèi)容是關(guān)于C語言版的算24游戲的代碼。
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
double sum(double a,double b)
{
return a+b;
}
double mi(double a,double b)
{
return a-b;
}
double mul(double a,double b)
{
}
double di(double a,double b)
{
return a/b;
}
{
int i;
double t[4];
for(i=0;i<4;i++)
des[i]=src[i];
}
void reorder4(int cp4,double re4)
{
switch(cp4)
{
case 0:
num[0]=re4;
num[1]=num[2];
num[2]=num[3];
break;
case 1:
num[1]=re4;
num[2]=num[3];
break;
case 2:
num[2]=re4;
break;
}
}
void reorder3(int cp3,double re3)
{
switch(cp3)
{
case 0:
num[0]=re3;
num[1]=num[2];
break;
case 1:
num[1]=re3;
break;
}
}
{
if(opt==sum)
return '+';
else if(opt==mi)
return '-';
else if(opt==mul)
else if(opt==di)
return '/';
}
{
double n0=num[0];
double n1=num[1];
double n2=num[2];
double n3=num[3];
switch(ta4)
{
case 0:
if(ta3==0)
printf("((%.0f%c%.0f)%c%.0f)%c%.0fn",n0,opc(op4),n1,opc(op3),n2,opc(op2),n3);
else if(ta3==1)
printf("(%.0f%c%.0f)%c(%.0f%c%.0f)n",n0,opc(op4),n1,opc(op2),n2,opc(op3),n3);
break;
case 1:
if(ta3==0)
printf("(%.0f%c(%.0f%c%.0f))%c%.0fn",n0,opc(op3),n1,opc(op4),n2,opc(op2),n3);
else if(ta3==1)
printf("%.0f%c((%.0f%c%.0f)%c%.0f)n",n0,opc(op2),n1,opc(op4),n2,opc(op3),n3);
break;
case 2:
if(ta3==0)
printf("(%.0f%c%.0f)%c(%.0f%c%.0f)n",n0,opc(op3),n1,opc(op2),n2,opc(op4),n3);
else if(ta3==1)
printf("%.0f%c(%.0f%c(%.0f%c%.0f))n",n0,opc(op2),n1,opc(op3),n2,opc(op4),n3);
break;
}
}
int main(void)
{
scanf("%d%d%d%d",&a,&b,&c,&d);
num[0]=(double)a;
num[1]=(double)b;
num[2]=(double)c;
num[3]=(double)d;
copyarr(num,numf);
copyarr(num,num4);
for(cp4=0;cp4<=2;cp4++)
{
for(i=0;i<4;i++)
{
cop4=ops[i];
reorder4(cp4,re4);
copyarr(num,num3);
for(cp3=0;cp3<=1;cp3++)
{
for(j=0;j<4;j++)
{
cop3=ops[j];
reorder3(cp3,re3);
for(k=0;k<4;k++)
{
cop2=ops[k];
if(re2==24)
{
printresult(numf,cp3,cp4,cop2,cop3,cop4);
system("pause");
return 0;
}
}
copyarr(num3,num);
}
}
copyarr(num4,num);
}
}
system("pause");
return 0;
}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。