#include
#include
#define M 4 //猜几个数字
//交换
void swap(int*a,int*b)
{
int t=*a;
a=*b;
b=t;
}
//将数组随机打乱
void random_shuffle(int a,int n)
{
int i;
for(i=0;i<n;i++)
{
int x=rand()%n;
int y=rand()%n;
if(x!=y) swap(a+x,a+y);
}
}
//生成数位不重复的M位全部数据,存在数组a中,并打乱,备用
int gen(int a)
{
int count=0,i,j;
int max=1;
for(i=0;i<M;++i,max*=10);
for(i=0;i<max;++i)
{
_Bool flag[10]={0};
int t=i;
for(j=0;j<M;++j)
if(flag[t%10]) break;
else flag[t%10]=1,t/=10;
if(j==M)
a[count++]=i;
}
random_shuffle(a,count);
return count;
}
void test(int answer,int player,int* A,int* B)
{
int i=0,j;
int answer_a[M]={0},player_a[M]={0};
A=*B=0;
while(answer||player)
{
answer_a[i]=answer%10;
player_a[i++]=player%10;
answer/=10;
player/=10;
}
for(i=0;i<M;++i)
for(j=0;j<M;++j)
if(player_a[i]==answer_a[j])
if(i==j) ++*A;
else ++*B;
}
//参数AB是上一轮猜测的反馈,
//如果得到猜中的信息表示下一把的开始
int guess(int A,int B)
{