热门IT资讯网

C语言版的算24游戏源码

发表于:2024-11-28 作者:热门IT资讯网编辑
编辑最后更新 2024年11月28日,下边代码内容是关于C语言版的算24游戏的代码。#include "stdafx.h"#include #include double sum(double a,double b){ return

下边代码内容是关于C语言版的算24游戏的代码。

#include "stdafx.h"#include #include 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;}
0