编程语言
首页 > 编程语言> > 算法入门经典p50-例3-4(简单统计)

算法入门经典p50-例3-4(简单统计)

作者:互联网

#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int data[50],target[50];
int number_data[15],number_target[15];
int main(){
    int n,i,a,b;
    int count = 0;
    while(scanf("%d",&n)!=EOF&&n){
        memset(number_data,0,sizeof(number_data));
        for(i=0;i<n;i++){
            scanf("%d",&data[i]);
            number_data[data[i]]++;
        }
        printf("Game %d:\n",++count);
        while(true){
            bool flag = true;
            for(i=0;i<n;i++){
                scanf("%d",&target[i]);
                if(target[i]!=0)flag = false;
            }
            if(flag)break;
            memset(number_target,0,sizeof(number_target));
            a = 0;
            b = 0;
            for(i=0;i<n;i++){
                if(data[i]==target[i]){
                    a++;
                }
                number_target[target[i]]++;
            }
            for(i=0;i<=9;i++){
                b += min(number_data[i],number_target[i]);
            }
            b -= a;
            printf("(%d,%d)\n",a,b);
        }
    }
    return 0;
}

 

标签:15,入门,int,p50,number,算法,include,data,target
来源: https://www.cnblogs.com/stevenzrx/p/15503406.html