UVa 340 Master-Mind Hints

很水的一道模拟题,只要用心做,不急,一步一步的来,很简单的~

#include<stdio.h>
#include<string.h>
int main()
{
    int n,a[1002],num[1002],game=1,s1[1002],s2[1002];
    while(scanf("%d",&n)!=EOF)
    {
        if(n==0) break;
        printf("Game %d:\n",game++);
        int i,j;
        for(i=0;i<n;i++)
        scanf("%d",&a[i]);
        while(1)
        {
            int sum=0,a=0,b=0;
            memset(s1,0,sizeof(s1));
            memset(s2,0,sizeof(s2));
            for(i=0;i<n;i++)
            {
                scanf("%d",&num[i]);
                sum+=num[i];
            }
            if(sum==0)break;
            for(i=0;i<n;i++)
            {
                if(a[i]==num[i]&&!s1[i]&&!s2[i])
				{
					a++;
					s1[i]=1;
					s2[i]=1;
				}
                else
					for(j=0;j<n;j++)
						if(a[j]==num[j]&&!s2[j]&&!s1[j])
						{
							a++;
							s1[j]=1;
							s2[j]=1;
						}
						else if(a[i]==num[j]&&!s1[i]&&!s2[j])
						{
							b++;
							s1[i]=1;
							s2[j]=1;
						}
            }
            printf("    (%d,%d)\n",a,b);
        }
    }
    return 0;
}



 

你可能感兴趣的:(UVa 340 Master-Mind Hints)