c语言24点游戏算法
c语言24点游戏算法,可以编译但是不知道错在哪里 麻烦有能力者帮忙看看,谢谢程序代码:
#include<stdlib.h> #include<stdio.h> #include<time.h> void main() { int i,j,k; int a1,a2,a3,a4; int x1,x2,x3,x4,x; do { srand(time(0)); for(i=0;i<1;i++) { j=rand()%10000; } a4=j/1000;a3=(j-a4*1000)/100; a2=(j-a4*1000-a3*100)/10;a1=j-a4*1000-a3*100-a2*10; } while(a1==a2||a1==a3||a1==a4||a2==a3||a2==a4||a3==a4); printf("Please input a number:"); do { scanf("%d",&x); x4=x/1000;x3=(x-x4*1000)/100; x2=(x-x4*1000-x3*100)/10;x1=x-x4*1000-x3*100-x2*10; if(x1==a1) { printf("a"); goto q1; } if(x1!=a1) { if(x1==a2) { printf("b"); goto q1; } if(x1!=a2) { if(x1==a3) { printf("b"); goto q1; } if(x1!=a3) { if(x1==a4) { printf("b"); goto q1; } if(x1!=a4) { goto q1; } } } } q1: if(x2==a1) { printf("b"); goto q2; } if(x2!=a1) { if(x2==a2) { printf("a"); goto q2; } if(x2!=a2) { if(x2==a3) { printf("b"); goto q2; } if(x2!=a3) { if(x2==a4) { printf("b"); goto q2; } if(x2!=a4) { goto q2; } } } } q2: if(x3==a1) { printf("b"); goto q3; } if(x3!=a1) { if(x3==a2) { printf("b"); goto q3; } if(x3!=a2) { if(x3==a3) { printf("a"); goto q3; } if(x3!=a3) { if(x3==a4) { printf("b"); goto q3; } if(x3!=a4) { } } } } q3: if(x4==a1) { printf("b"); goto q4; } if(x4!=a1) { if(x4==a2) { printf("b"); goto q4; } { if(x4==a3) { printf("b"); goto q4; } if(x4!=a3) { if(x4==a4) { printf("a"); goto q4; } if(x4!=a4) { goto q4; } } } } q4: printf("\n"); } while(a1!=x1||a2!=x2||a3!=x3||a4!=x4); printf("You are right!\nThanks for your support.\nThe game is made by 胡潇月~"); getchar(); }
[此贴子已经被作者于2017-12-12 17:59编辑过]