题目链接L1-104 九宫格
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int n, mapp[10][10], a[10];
int dx[10]={0, 1, 1, 1, 4, 4, 4, 7, 7, 7};
int dy[10]={0, 1, 4, 7, 1, 4, 7, 1, 4, 7};
bool check() {int cnt = 0;for (int i = 1; i <= 9; i++) {if (a[i] == 1) cnt++;}if (cnt == 9) return true;else return false;
}
int main()
{cin >> n;while (n-- ) {for (int i = 1; i <= 9; i++) {for (int j = 1; j <= 9; j++) {cin >> mapp[i][j];}}int row=0, col=0, d33=0; // 行 列 3*3for (int i = 1; i <= 9; i++) {memset(a, 0, sizeof(a));for (int j = 1; j <= 9; j++) {a[mapp[i][j]]++;}if (!check()) row++;}for (int i = 1; i <= 9; i++) {memset(a, 0, sizeof(a));for (int j = 1; j <= 9; j++) {a[mapp[j][i]]++;}if (!check()) col++;}for (int k = 1; k <= 9; k++){memset(a, 0, sizeof(a));for (int i = dx[k]; i <= dx[k]+2; i++) {for (int j = dy[k]; j <=dy[k]+2; j++) {a[mapp[i][j]]++;}}if (!check()) d33++;}// cout << row << " " << col << " " << d33 <<endl;if (!row&&!col&&!d33) cout << "1" << endl;else cout << "0" << endl;}
}