UVa-340 Master-Mind Hints

#include<iostream>
#include<cstdio>
#include<cstring>
#include<iomanip>
using namespace std;
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n,cnt=0;
    while(cin>>n)
    {
        if(n==0) break;
        ++cnt;
        cout<<"Game "<<cnt<<":"<<endl;
        int ans[1010]={};
        for(int i=1;i<=n;i++)
            cin>>ans[i];
        while(1)
        {
            int a[1010]={},ans1[1010]={};
            for(int i=1;i<=n;i++)
            {
                cin>>a[i];
                ans1[i]=ans[i];
            }
            if(a[1]==0) break;
            int cnt1=0,cnt2=0;
            for(int i=1;i<=n;i++)
            {
                if(a[i]==ans1[i])
                {
                    ans1[i]=a[i]=0;
                    ++cnt1;
                }
            }
            for(int i=1;i<=n;i++)
            {
                if(a[i]==0) continue;
                for(int j=1;j<=n;j++)
                {
                    if(ans1[j]==0) continue;
                    if(a[i]==ans1[j])
                    {
                        a[i]=ans1[j]=0;
                        ++cnt2;
                    }
                }
            }
            printf("    (%d,%d)\n",cnt1,cnt2);
        }
    }
}

posted on 2015-02-14 03:13  windrises  阅读(110)  评论(0编辑  收藏  举报

导航