任务4完成

main
高世波 1 year ago
parent b953453448
commit d7f2ce0103

28
.vscode/tasks.json vendored

@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe 生成活动文件",
"command": "C:\\Users\\GaoShiBo\\software\\mingw64\\bin\\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}

@ -1,10 +1,31 @@
#include "myMatrix.h"
int fillMatrix(){
//todo
int fillMatrix(int matrixArr[9][9], int row, int col){
if(row==9){
return 1;
}
if(col==9){
return fillMatrix(matrixArr,row+1,0);
}
if(matrixArr[row][col]!=0){
return fillMatrix(matrixArr, row, col+1);
}
for(int i=1;i<=9;i++){
matrixArr[row][col]=i;
if(checkMatrix(matrixArr,0)){
if(fillMatrix(matrixArr,row,col+1)){
return 1;
}
matrixArr[row][col]=0;
}else{
matrixArr[row][col]=0;
}
}
return 0;
}
int main(){
int main()
{
int board0[9][9] = {{5, 3, 0, 0, 7, 0, 0, 0, 0},
{6, 0, 0, 1, 9, 5, 0, 0, 0},
{0, 9, 8, 0, 0, 0, 0, 6, 0},
@ -32,12 +53,22 @@ int main(){
{0, 6, 0, 0, 0, 0, 2, 8, 0},
{0, 0, 0, 4, 1, 9, 0, 0, 5},
{0, 0, 0, 0, 8, 0, 0, 7, 9}};
printf("The original Sudoku matrix: \n");
matrixOutput(board1);
if(checkMatrix(board1,1)){
fillMatrix();
}else{
matrixOutput(board0);
if (checkMatrix(board0, 1))
{
if (fillMatrix(board0, 0, 0))
{
printf("\nThe solution of Sudoku matrix:\n");
matrixOutput(board0);
}
else
{
printf("\nNo solution!");
}
}
else
{
printf("\nNo solution!");
}
return 0;

Binary file not shown.
Loading…
Cancel
Save