# 五连珠

## 代码

```#include<cstdio>
#include<cstring>

using namespace std;

int T, a1[11], a2[11], b1[11], b2[11], c1[2], c2[2];
int ax[51], ay[51], bx[51], by[51], x, shun[51];

int main() {
scanf("%d", &T);
while (T--) {
memset(a1, 0, sizeof(a1));//初始化
memset(a2, 0, sizeof(a2));
memset(b1, 0, sizeof(b1));
memset(b2, 0, sizeof(b2));
memset(c1, 0, sizeof(c1));
memset(c2, 0, sizeof(c2));

for (int i = 1; i <= 5; i++)
for (int j = 1; j <= 5; j++) {
scanf("%d", &x);
ax[x] = i;//记录每个数字在第一个矩阵中的坐标
ay[x] = j;
}
for (int i = 1; i <= 5; i++)
for (int j = 1; j <= 5; j++) {
scanf("%d", &x);
bx[x] = i;//记录每个数字在第二个矩阵中的坐标
by[x] = j;
}

for (int i = 1; i <= 25; i++) {
scanf("%d", &shun[i]);
}
for (int i = 1; i <= 25; i++) {//按顺序划掉
a1[ax[shun[i]]]++;//更新那一行，那一列被划掉的数多了一个
a2[bx[shun[i]]]++;
b1[ay[shun[i]]]++;
b2[by[shun[i]]]++;
if (ax[shun[i]] == ay[shun[i]]) c1[0]++;//在左上右下的对角线上
if (bx[shun[i]] == by[shun[i]]) c2[0]++;
if (ax[shun[i]] + ay[shun[i]] == 6) c1[1]++;//在右上左下的对角线上
if (bx[shun[i]] + by[shun[i]] == 6) c2[1]++;
if (a1[ax[shun[i]]] == 5 || b1[ay[shun[i]]] == 5 || c1[0] == 5 || c1[1] == 5) {//第一个矩阵满足了
if (a2[bx[shun[i]]] == 5 || b2[by[shun[i]]] == 5 || c2[0] == 5 || c2[1] == 5) {//第二个矩阵也满足了
printf("0\n");//两个同时满足输出 0
break;
}
printf("1\n");//只有第一个满足输出 1
break;
}
else if (a2[bx[shun[i]]] == 5 || b2[by[shun[i]]] == 5 || c2[0] == 5 || c2[1] == 5) {//第一个每满足，第二个满足了
printf("2\n");//输出 2
break;
}
}
}

return 0;
}```