/*读了老半天才把题读懂,读懂了题输出格式没注意,结果re了两次。 题意:先给一串数字S,然后每次给出对应相同数目的的一串数字Si,然后优先统计Si和S对应位相同并且相等的个数L,在统计不在对应位上但相等的的个数R. 当Si全0时,表示结束。 每个数只能用一次。 例如:有 S 1 3 5 5 S1 1 1 2 3 S2 4 3 3 5 Si . . . . 0 0 0 0 对于S1:则第一步只有第一个对应相等,所以L = 1 就还剩下3 5 5 1 2 3,在统计R,下面只有3和上面的3相同,所以R = 1; 对于S2:L = 2,第二个位置和第四个位置对应相等。 就还剩下1 5 4 3,所以R = 0;依次类推。 */ #include <iostream> #include <fstream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <climits> #include <cstring> #include <string> #define N 1005 using namespace std; int n; int a[N], b[N], c[N]; int main() { int i, j, t = 1, l, r; while (cin>>n, n) { cout<<"Game "<<t++<<':'<<endl; for (i = 0; i < n; i++) cin>>a[i]; while (true) { for (i = 0; i < n; i++) c[i] = a[i]; l = r = 0; for (i = 0; i < n; i++) { cin>>b[i]; if (b[i] == c[i])/**< 统计对应位相等l的个数 */ { l++; c[i] = 0;/**< 置相等位0,统计r时不影响 */ b[i] = -1; } } if (!b[0]) break; for (i = 0; i < n; i++) { if (b[i] == -1) continue; for (j = 0; j < n; j++) { if (b[i] == c[j])/**< 统计r的个数 */ { r++; c[j] = 0; break; } } } cout<<" "<<'('<<l<<','<<r<<')'<<endl; } } return 0; }
相关文章: