紧急求助:用c程序编这个小游戏,谁都会!
而且绝对原创,希望楼主采纳。
# include & ltstdio.h & gt
# include & ltstdlib.h & gt
# include & lttime.h & gt
# include & ltmath.h & gt
#定义尺寸4
#定义时间12
void main()
{
int i,a[SIZE],b[SIZE],j,counta=0,countb=0,x,m,n,t,size=SIZE,times = TIMES
做
{
srand(time(NULL));
for(I = 0;我& lt尺寸;i++)
{
a[I]= rand()% 10;/*系统生成四个不相同的随机数*/
}
}
而(!(答[0]!= a[1]& amp;& amp一个[0]!= a[2]& amp;& amp一个[0]!= a[3]& amp;& ampa[1]!= a[2]& amp;& ampa[1]!= a[3]& amp;& amp答[2]!= a[3]));
Printf("请猜%d个不同的数字:\n ",大小);/*猜四个数字*/
for(j = 0;j & lt= TIMESj++)
{
做
{
scanf("%d ",& ampx);
b[0]= x/1000;b[1]=(x/100)% 10;b[2]=(x/10)% 10;b[3]= x % 10;
if(b[0]!= b[1]& amp;& ampb[0]!= b[2]& amp;& ampb[0]!= b[3]& amp;& ampb[1]!= b[2]& amp;& ampb[1]!= b[3]& amp;& ampb[2]!= b[3]& amp;& ampb[0]& lt;=9)破;
Else printf("输入错误,请重新输入!\ n ");
}
而(!(b[0]!= b[1]& amp;& ampb[0]!= b[2]& amp;& ampb[0]!= b[3]& amp;& ampb[1]!= b[2]& amp;& ampb[1]!= b[3]& amp;& ampb[2]!= b[3])| | b[0]& gt;9);
counta = 0;countb = 0;
for(m = 0;m & lt=3;m++)
{ if(a[m]= = b[m])counta = counta+1;}
for(n = 0;n & lt=3;n++)
{
for(t = 0;t & lt=3;t++)
if(a[n]= = b[t])count b++;
}
countb = count b-counta;
printf("%dA%dB\n ",counta,countb);
if(counta = = 4)break;
if(j==11)破;
Printf("请再次输入%d个不同的数字:\n ",大小);
}
If(counta==4) printf("你猜对了,太棒了!\ n ");
Else printf("你已经猜了%d次了,不能再猜了!结果是% d% d% d \ n ",次,A [0],A [1],A [2],A[3]);
}