刚了一个晚上,终于刚出来了,然而有一个大bug,随时会退出,怎么解决啊
#include<stdio.h>#include<windows.h>
#include<stdlib.h>
#include<time.h>
int main(void)
{
int origin[16],i,m,l,r,p[4][4],(*pair)[4],j,x=0,y=9;
char (*cover)[4],c[4][4]= {{'?','?','?','?'},{'?','?','?','?'},{'?','?','?','?'},{'?','?','?','?'}};
srand((unsigned)time(NULL));
for(i=0; i<8; i++)
{
origin[i]=origin[i+8]=(rand()%(y-x))+x;
x+=10;
y+=10;
}
for(i=0; i<30; i++)
{
l=rand()%16;
r=rand()%16;
m=origin[l];
origin[l]=origin[r];
origin[r]=m;
}
i=0;
for(pair=p; pair<p+4; pair++)
{
for(j=0; j<4; j++)
{
(*pair)[j]=origin[i];
printf("%4d",(*pair)[j]);
i+=1;
}
printf("\n");
}
Sleep(10000);
system("cls");
for (cover = c; cover < c+4; cover++)
{
for (i = 0; i < 4; i++)
{
printf("%4c",(*cover)[i]);
}
printf("\n");
}
int a,b,e,f,t=0,pairs=8;
while(pairs>0)
{
printf("Please select a position (or coordinate) of number: ");
scanf("%d %d", &a, &b);
printf("Please select another one you think is the pair of previous one: ");
scanf("%d %d", &e, &f);
c[a-1][b-1]=p[a-1][b-1];
c[e-1][f-1]=p[e-1][f-1];
t+=1;
for (cover = c; cover < c+4; cover++)
{
for (i = 0; i < 4; i++)
{
if((*cover)[i]=='?')
{
printf("%3c",(*cover)[i]);
}
else
{
printf("%3d",(*cover)[i]);
}
}
printf("\n");
}
Sleep(2500);
system("cls");
if(p[a-1][b-1]==p[e-1][f-1])
{
pairs-=1;
for (cover = c; cover < c+4; cover++)
{
for (i = 0; i < 4; i++)
{
if((*cover)[i]=='?')
{
printf("%3c",(*cover)[i]);
}
else
{
printf("%3d",(*cover)[i]);
}
}
printf("\n");
}
}
else
{
c[a-1][b-1]='?';
c[e-1][f-1]='?';
for (cover = c; cover < c+4; cover++)
{
for (i = 0; i < 4; i++)
{
printf("%3c",(*cover)[i]);
}
printf("\n");
}
}
}
printf("Congratulation! It took you %d times to find all pairs.",t);
return 0;
}