这个题目巨长。略过,A同列相同元素统计即可。A是数字在两个序列中出现过位置相同
主要是B,数字在两个序列中都出现过的次数 = 数字在两个序列中都出现过但位置不对 + 数字在两个序列中都出现过位置相同
B = 数字在两个序列中都出现过的次数 - A;
数字在两个序列中出现的次数应该是取次数较少的,例如在答案序列中出现过2次,测试序列中出现过3次,实际上在两个序列中都出现过两次,而不是都出现过三次,所以每次取最小
#include<stdio.h>
int main(void)
{
int a[1000], b[1000], n;
int kase = 0;
while(scanf("%d", &n) == 1 && n)
{
for(int i = 0; i < n; i++)
scanf("%d", &a[i]);
printf("Game %d:\n", ++kase);
while(1)
{
int A = 0, B = 0;
for(int i = 0; i < n; i ++)
{
scanf("%d", &b[i]);
if (a[i] == b[i]) A++;
}
if (b[0] == 0) break;
for(int d = 1; d <= 9; d++)
{
int c1 = 0, c2 = 0;
for(int i = 0; i < n; i++)//统计两个序列中出现的次数
{
if (a[i] == d) c1++;
if (b[i] == d) c2++;
}
if (c1 < c2) B+= c1; else B+=c2;//两个序列中都出现的次数min(c1, c2)
}
printf(" (%d,%d)\n", A, B-A);
}
}
}