#include <stdio.h>
#include <string.h>
#define N 13
int A[N][N];
int tag[10];
bool JudgeRow()
{
for (int i=1;i<=9;++i)
{
memset(tag,0,sizeof(int)*10);
for (int j=1;j<=9;++j)
{
tag[A[i][j]]=1;
}
for (int j=1;j<=9;++j)
{
if (tag[j]==0)
{
return false;
}
}
}
return true;
}
bool JudgeCol()
{
for (int i=1;i<=9;++i)
{
memset(tag,0,sizeof(int)*10);
for (int j=1;j<=9;++j)
{
tag[A[j][i]]=1;
}
for (int j=1;j<=9;++j)
{
if (tag[j]==0)
{
return false;
}
}
}
return true;
}
bool JudgeNINE()
{
for (int i=1;i<=7;i+=3)
{
for (int j=1;j<=7;j+=3)
{
memset(tag,0,sizeof(int)*10);
for (int p=i;p<=i+3;++p)
{
for (int q=j;q<=j+3;++q)
{
tag[A[p][q]]=1;
}
}
for (int k=1;k<=9;++k)
{
if(tag[k]==0) return false;
}
}
}
}
int main(int argc,char **argv)
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n;
while(scanf("%d",&n)==1)
{
for (int k=0;k<n;++k)
{
for (int i=1;i<=9;++i)
{
for (int j=1;j<=9;++j)
{
scanf("%d",&A[i][j]);
}
}
if (JudgeRow() && JudgeCol() && JudgeNINE())
{
printf("Right\n");
}
else
{
printf("Wrong\n");
}
}
}
}
6.15判断数独
最新推荐文章于 2021-11-24 15:03:40 发布