diff --git a/数独2.cpp b/数独2.cpp deleted file mode 100644 index fcf190b..0000000 --- a/数独2.cpp +++ /dev/null @@ -1,100 +0,0 @@ -#include -#include -#include - -void assignNumbers(int matrix[3][9]) -{ - srand(time(NULL)); - int num[10]={0,1,2,3,4,5,6,7,8,9}; - for (int i = 0; i < 3; i++) - { - for (int j = 0; j < 3; j++) - { - int randomNumber = rand() % 10; - int random=rand()%10; - while (matrix[i][randomNumber] != 0) - { - randomNumber = rand() % 10; - } - while(num[random]==10) - { - random=rand()%10; - } - matrix[i][randomNumber] =num[random] ; - num[random]=10; - } - } -} -void shuffleMatrix(int matrix[3][9])//Ï´ÅÆËã·¨ - { - for (int i = 2; i >= 0; i--) - { - for (int j = 8; j > 0; j--) - { - int row1 = i; - int col1 = j; - int row2 = rand() % (i + 1); - int col2 = rand() % (j + 1); - - int temp = matrix[row1][col1]; - matrix[row1][col1] = matrix[row2][col2]; - matrix[row2][col2] = temp; - } - } -} -void mergeMatrices(int matrix1[3][9], int matrix2[3][9], int matrix3[3][9], int mergedMatrix[9][9]) //ºÏ²¢¾ØÕó -{ - // ¸´ÖƵÚÒ»¸ö¾ØÕóµÄÄÚÈݵ½Ç°ÈýÐÐ - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 9; j++) { - mergedMatrix[i][j] = matrix1[i][j]; - } - } - - // ¸´ÖƵڶþ¸ö¾ØÕóµÄÄÚÈݵ½ÖмäÈýÐÐ - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 9; j++) { - mergedMatrix[i + 3][j] = matrix2[i][j]; - } - } - - // ¸´ÖƵÚÈý¸ö¾ØÕóµÄÄÚÈݵ½×îºóÈýÐÐ - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 9; j++) { - mergedMatrix[i + 6][j] = matrix3[i][j]; - } - } -} -void print(int board[9][9]) - { - 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 != 0) - { - printf("| "); - } - printf("%d ", board[i][j]); - } - printf("\n"); - } -} - -int main() -{ - int merge[9][9]={0}; - int mat1[3][9]={0}; - int mat2[3][9]={0}; - int mat3[3][9]={0}; - assignNumbers(mat1); - assignNumbers(mat2); - assignNumbers(mat3); - mergeMatrices(mat1,mat2,mat3,merge); - print(merge); - return 0; -}