#include int main ( ) { int i,j,number,s,q,p,t,g; printf("“The original Sudoku matrix:"); printf("\n"); char board[9][9]={{'5','3','4','6','7','8','9','2','1'}, {'6','7','2','1','9','5','3','4','6'}, {'1','9','8','3','4','2','5','8','7'}, {'8','5','9','7','6','1','4','2','3'}, {'4','2','6','8','5','3','7','9','1'}, {'7','1','3','9','2','4','8','5','6'}, {'9','6','1','5','3','7','2','8','4'}, {'2','8','7','4','1','9','6','3','5'}, {'3','4','5','2','8','6','1','7','9'}}; for (i=0;i<9;i++) { for (j=0;j<9;j++) { printf(" %c ",board[i][j]); } printf("\n"); } //此处引入1 int c[10]={0,0,0,0,0,0,0,0,0,0};//用来储存数字出现的个数 //下面小矩阵的判断 int w[10]={1,2,3,4,5,6,7,8,9}; int k=0; for(t=3;t<=9;t=t+3) { for(g=3;g<=9;g=g+3) { for(i=t-3;i1) { printf("False:Invalid initial Sudoku matrix!"); printf("The number %d in the block %d has been used!",q,w[k]); return 0; } } k++; for(s=0;s<=9;s++)c[s]=0; } } //完成行的判断 for(i=0;i<9;i++) { for(number=1;number<=9;number++) { for(j=0;j<9;j++) { if(board[i][j]==number+'0') c[number]++; } } for(q=1;q<=9;q++) { if(c[q]>1) { printf("False:Invalid initial Sudoku matrix!\n"); printf("The number %d in the col %d has been used!",q,i+1); return 0 ; } } for(p=0;p<10;p++) { c[p]=0; } } //同理列的判断 for(i=0;i<9;i++) { for(number=1;number<=9;number++) { for(j=0;j<9;j++) { if(board[j][i]==number+48) c[number]++;} } for(q=1;q<=9;q++) { if(c[q]>1) { printf("False:Invalid initial Sudoku matrix!"); printf("The number %d in the column %d has been used!",q,i+1); return 0; } } for(p=0;p<10;p++) { c[p]=0; } } return 0; }