L1-104 九宮格 分數 20

Frodnx發表於2024-08-27
#include <bits/stdc++.h>
using namespace std;
int arr[10][10];
int main()
{
    int n;
    cin >> n;
    for(int t = 1; t <= n; ++ t)
    {
        for(int j = 1; j <= 9; ++ j)
            for(int k = 1; k <= 9; ++ k)
            	cin >> arr[j][k];
        int flag = true;
        for(int i = 1; i <= 9; ++ i)
        {
        	map<int,bool> hash1;
        	map<int,bool> hash2;
        	for(int j = 1; j <= 9; ++ j)
        	{
        		if(arr[i][j] <= 0 || arr[j][i] <= 0) flag = false;
        		if(arr[i][j] >= 10 || arr[j][i] >= 10) flag = false;
        		if(hash1[arr[i][j]] == true) flag = false;
        		else hash1[arr[i][j]] = true;
        		if(hash2[arr[j][i]] == true) flag = false;
        		else hash2[arr[j][i]] = true;
			}
		}
		for(int i = 0; i <= 8; ++ i)
		{
			int ii = 3 * (i % 3);
			int jj = 3 * (i / 3);
			map<int,bool> hash;
			for(int j = 1; j <= 3; ++ j)
			{
				for(int k = 1; k <= 3; ++ k)
				{
					if(hash[arr[ii + j][jj + k]] == true) flag = false;
        			else hash[arr[ii + j][jj + k]] = true;
				}
			}
		}
		if(flag) cout << 1;
		else cout << 0;
		if(t != n) cout << endl;
    }
    return 0;
}

相關文章