实在是闲的无聊所做。。。
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(){
time_t t;
char ch;
int i,j,k;
int a,b;
int num[4];
int inputNum[4];
int isE;
srand((unsigned)time(&t));
while(ch!='e'){
i=0;
for (j=0;j<=3;j++) {
do{
isE=0;
num[j]=(rand()%10);
for (k=0;k<j;k++){
if (num[j]==num[k]) isE=1;
}
}while(isE==1);
}
printf("Guess Please:\n");
while(i<=7){
a=0;b=0;
scanf("%d %d %d %d",&(inputNum[0]),&(inputNum[1]),&(inputNum[2]),&(inputNum[3]));
for (j=0;j<=3;j++){
for (k=0;k<=3;k++){
if ((inputNum[j]==num[k])&&(j==k)) a++;
else if (inputNum[j]==num[k]) b++;
}
}
if (a==4){printf("You Win!!!\n");break;}
printf("Round %d :%d %d %d %d -> %dA%dB\n",i+1,inputNum[0],inputNum[1],inputNum[2],inputNum[3],a,b);
i++;
}
if (i==8){
printf("Anwser is %d %d %d %d!\n",num[0],num[1],num[2],num[3]);
printf("You Loss!!\n");
}
ch=getch();
}
转载请注明出处,禁止用于任何商业用途,否则后果自负!