2009-02-26 19:33:10來源不明
ACM 340 Q340: Master-Mind Hints
/************************************************************/
#include<stdio.h>#include<stdlib.h>
main()
{
int n,time=0;
int ans[1001],guess[1001],temp[1001];
while(scanf("%d",&n)==1&&n!=0)
{
time++;
printf("Game %d:\n",time);
int a,b,c;
for(a=0;a<n;a++)
scanf("%d",&ans[a]);
while(1)
{
int A=0,B=0,flag=0;
for(a=0;a<n;a++)
{
scanf("%d",&guess[a]);
flag=flag+guess[a];
}
if(flag==0)
break;
for(a=0;a<n;a++)
temp[a]=ans[a];
for(a=0;a<n;a++)
if(temp[a]==guess[a])
{
A++;
temp[a]=-1;
guess[a]=-2;
}
for(a=0;a<n;a++)
{
for(b=0;b<n;b++)
{
if(guess[a]==temp[b])
{
B++;
temp[b]=-1;
guess[a]=-2;
break;
}
}
}
printf(" (%d,%d)\n",A,B);
}
}
return 0;
}