From 49d59717d19027a781629bb0781f01f3d0ac584d Mon Sep 17 00:00:00 2001 From: psc2uwxgy Date: Thu, 7 Nov 2024 22:41:58 +0800 Subject: [PATCH] ADD file via upload --- function.2.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 function.2.cpp diff --git a/function.2.cpp b/function.2.cpp new file mode 100644 index 0000000..a78db3c --- /dev/null +++ b/function.2.cpp @@ -0,0 +1,52 @@ +#include +#include +#include + +int main(){ + + srand(time(NULL)); + int board[9][9]; + + int num[9]={1,2,3,4,5,6,7,8,9}; + for(int i =0;i<9;i++) + { + if(i%3==0) + { + for(int j =0;j<9;j++) + { + int k =rand()%9; + int temp = num[j]; + num[j] = num[k]; + num[k] = temp; + } + } + for(int j = 0;j<9;j++) //定义矩阵各元素为0 + { + board[i][j] = 0; + } + for(int m = 0;m<3;m++) + { + int index; + do{ + index = rand()%9; + }while(board[i][index]!=0); + board[i][index] = num[3*(i%3)+m]; + } + } + + printf("The original Sudoku matrix: \n"); //格式化输出 + for(int i=0;i<9;i++){ + if(i%3==0){ + printf("-------------\n"); + } + for(int j=0;j<9;j++){ + if(j%3==0||j==9){ + printf("|"); + } + printf("%d",board[i][j]); + } + printf("|\n"); + }printf("-------------\n"); + + return 0; + }