数字控们有福啦,进来瞧一瞧啊
http://pan.baidu.com/share/link?shareid=2676007940&uk=4180621342不才做了个猜数字的小游戏,希望大家支持一下
程序代码:#include <stdio.h>
#include <time.h>
int f[10000];
int check(int i,int a,int b,int c,int d,int s,int t)
{
int j,aa,bb,cc,dd,ss,tt=0,ee=i;
dd=ee%10; ee/=10;
cc=ee%10; ee/=10;
bb=ee%10; ee/=10;
aa=ee;
ss=(a==aa)+(b==bb)+(c==cc)+(d==dd);
if (s!=ss) return 0;
int p[10];
for (j=0; j<10; j++) p[j]=0;
p[aa]++; p[bb]++; p[cc]++; p[dd]++;
if (p[a]>0) tt++;
if (p[b]>0) tt++;
if (p[c]>0) tt++;
if (p[d]>0) tt++;
if (t!=tt) return 0;
return 1;
}
int num(int e)
{
int a,b,c,d,s=1;
d=e%10; e/=10;
c=e%10; e/=10;
b=e%10; e/=10;
a=e;
if (b!=a) s++;
if (c!=a && c!=b) s++;
if (d!=c && d!=b && d!=a) s++;
return s;
}
int main()
{
srand(time(NULL));
int i,a,b,c,d,e,s,t,total=10000;
while (1)
{
t=0;
for (i=0; i<10000; i++)
if (!f[i] && t<num(i))
{
e=i; t=num(i);
}
d=e%10; e/=10;
c=e%10; e/=10;
b=e%10; e/=10;
a=e;
printf("%d %d %d %d\n",a,b,c,d);
if (total==1) break;
scanf("%d%d",&t,&s);
for (i=0; i<10000; i++)
if (!f[i] && !check(i,a,b,c,d,s,t))
{
f[i]=1;
total--;
}
}
system("pause");
}