soj dsa extra 1002 sudoku

来源:互联网 发布:sql start with 树状 编辑:程序博客网 时间:2024/05/21 06:33

 貌似是一道长得吓人的题。但是我的简单直接的想法居然也能ac。

#include <cstdio>int main(){  int testNumber;  scanf("%d",&testNumber);  bool inputFlag=true;  int sudoku[21][21];  int tempInput;  while(testNumber--){    bool sflag=true;    if(inputFlag) getchar();    for(int row=1;row<=9;row++){      int judge[11]={0};      for(int col=1;col<=9;col++){scanf("%d",&tempInput);sudoku[row][col]=tempInput;judge[tempInput]++;      }      for(int i=1;i<=9;i++)if(judge[i]!=1) sflag=false;    }    for(int col=1;col<=9;col++){      int judge[11]={0};      for(int row=1;row<=9;row++){judge[sudoku[row][col]]++;}      for(int i=1;i<=9;i++)if(judge[i]!=1) sflag=false;    }    for(int bigRow=1;bigRow<=3;bigRow++){      for(int bigCol=1;bigCol<=3;bigCol++){int judge[11]={0};for(int smallRow=1;smallRow<=3;smallRow++){  for(int smallCol=1;smallCol<=3;smallCol++)    judge[sudoku[3*(bigRow-1)+smallRow][3*(bigCol-1)+smallCol]]++;}for(int i=1;i<=9;i++)  if(judge[i]!=1) sflag=false;      }    }    if(sflag) printf("Right\n");    else printf("Wrong\n");    inputFlag=false;  }  return 0;}
基本上就是一个很直接的想法。先检查行,再检查列,最后在检查每个宫


原创粉丝点击