UVA-340 Master-Mind Hints (猜数字)

分析:猜数字游戏,水题
 
 
 
 
 
 
#include<cstdio>  
#include<algorithm>  
#include<map>  
using namespace std;  
const int N = 1005;  
int  a[N], b[N], c, d;  
int main()  
{  
    int n, cas = 0;  
    while (scanf ("%d", &n), n)  
    {  
        map<int, int> aa;  
        printf ("Game %d:\n", ++cas);  
        for (int i = 0; i < n; ++i)  
        {  
            scanf ("%d", &a[i]);  
            ++aa[a[i]];  
        }  
        while (1)  
        {  
            map<int, int> bb;  
            for (int i = c = d = 0; i < n; ++i)  
            {  
                scanf ("%d", &b[i]);  
                ++bb[b[i]];  
                if (a[i] == b[i]) c++;  
            }  
            if (!b[0]) break;  
            for (int i = 1; i <= 9; ++i)  
                d += min (aa[i], bb[i]);  
            printf ("    (%d,%d)\n", c, d - c);  
        }  
    }  
    return 0;  
}  

你可能感兴趣的:(Master-Mind,UVA-340)