源代码如下:
#include "stdio.h"
#include "math.h"
main()
{
int i,k,count,same,similar,m1,m2,m3,m4,n1,n2,n3,n4,result,a[4],b[4];
m1=rand();
m2=rand();
m3=rand();
m4=rand();
n1=m1%10;
n2=m2%10;
while(n2==n1) {m2=rand();n2=m2%10;}
n3=m3%10;
while(n3==n2||n3==n1) {m3=rand();n3=m3%10;}
n4=m4%10;
while(n4==n3||n4==n2||n4==n1) {m4=rand();n4=m4%10;}
result=n1*1000+n2*100+n3*10+n4;
count=2;
while(count!=0)
{
for(i=0;i<4;i++)
scanf("%d",&a);
b[0]=n1;b[1]=n2;b[2]=n3;b[3]=n4;
same=0;similar=0;
for(i=0;i<4;i++)
{
if(a==b) same=same+1;
for(k=0;k<4&&k!=i;k++)
{
if(a==b[k]) similar=similar+1;
}
}
if(same!=4) {printf("%dA,%dB",same,similar);count=count-1;}
else { printf("well done!");count=0; }
}
printf("the result is %d",result);
} |