1 #include<iostream> 2 using namespace std; 3 int main() 4 { 5 int n,kase = 0; 6 while (cin >> n,n != 0) 7 { 8 int a[500] = { 0 },b[100],mark =0,c1=0,c2=0; 9 for (int i = 0; i < n; i++) 10 cin >> a[i]; 11 while (true) 12 { 13 mark = 0; 14 for (int i = 0; i < n; i++) 15 { 16 cin >> b[i]; 17 if (a[i] == b[i]) 18 mark++; 19 } 20 if (b[0] == 0) break; 21 int Sum = 0; 22 for (int i = 1; i <=9; i++) 23 { 24 c1 = 0, c2 = 0; 25 for (int j = 0; j < n; j++) 26 { 27 if (a[j] == i) c1++; 28 if (b[j] == i) c2++; 29 } 30 if (c1 < c2) Sum += c1; else Sum += c2; 31 } 32 cout << "Game " << kase++ << endl; 33 cout << "(" << mark << "," << Sum - mark << ")" << endl; 34 } 35 } 36 return 0; 37 }
比较巧妙的是处理数字都存在但位置不对的方式,采取的方式是外层循环遍历1至9,用一个内层循环计两数组的数字的个数