题目地址:点击打开链接
C++代码:
#include<iostream> #include<cstring> using namespace std; const int maxsize=2000; int main() { int a[maxsize],b[maxsize],flag_a[maxsize],flag_b[maxsize]; int game; int n; game=1; while(cin>>n) { if(n==0)break; int i; cout<<"Game "<<game++<<":"<<endl; for(i=0;i<n;++i) cin>>a[i]; while(true) { for(i=0;i<n;++i) cin>>b[i]; if(b[0]==0)break; int A,B; A=B=0; memset(flag_a,0,maxsize*sizeof(int)); memset(flag_b,0,maxsize*sizeof(int)); int j; for(i=0;i<n;++i) { if(a[i]==b[i]) { ++A; flag_a[i]=flag_b[i]=1; } } for(i=0;i<n;++i) { for(j=0;j<n;++j) { if(i!=j&&a[i]==b[j]&&flag_a[i]==0&&flag_b[j]==0) { flag_a[i]=1; flag_b[j]=1; ++B; } } } cout<<" "<<"("<<A<<","<<B<<")"<<endl; } } return 0; }