#include<iostream> /// ac
#include<cstdio>
using namespace std;
int main()
{
int a[200],n,b[200],i,i1,i2,c[200];
int f,k,ans;
while(scanf("%d",&n)!=EOF,n)
{
for(i=1; i<=n; i++)
scanf("%d%d%d",&a[i],&b[i],&c[i]);
k=0;
for(i=1000; i<=9999; i++)
{
f=1;
int bb;
int cc;
int a1[5],a2[5];
for(i1=1; i1<=n; i1++)
{
a1[1]=i%10;
a2[1]=a[i1]%10;
a1[2]=i%100/10;
a2[2]=a[i1]%100/10;
a1[3]=i%1000/100;
a2[3]=a[i1]%1000/100;
a1[4]=i/1000;
a2[4]=a[i1]/1000;
cc=bb=0;
for(i2=1; i2<=4; i2++)
if(a1[i2]==a2[i2])
cc++;
if(cc!=c[i1])
{
f=0;
break;
}
for(i2=1; i2<=4; i2++)
{
for(int j=1; j<=4; j++)
if(a2[i2]==a1[j])
{
bb++;
a1[j]=-1; /// 只能匹配一次
break;
}
}
if(bb!=b[i1])
{
f=0;
break;
}
}
if(f==1)
{
k++;
ans=i;
}
}
if(k>=2) printf("Not sure\n"); /// 不止一个解
else printf("%d\n",ans);
}
return 0;
}
hdu1172猜数字
最新推荐文章于 2021-02-17 21:48:11 发布