|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
|
|
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])//ϴ<><CFB4><EFBFBD>㷨
|
|
|
|
|
{
|
|
|
|
|
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]) //<2F>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
// <20><><EFBFBD>Ƶ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
|
for (int j = 0; j < 9; j++) {
|
|
|
|
|
mergedMatrix[i][j] = matrix1[i][j];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>Ƶڶ<C6B5><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5>м<EFBFBD><D0BC><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
|
for (int j = 0; j < 9; j++) {
|
|
|
|
|
mergedMatrix[i + 3][j] = matrix2[i][j];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
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++) //<2F><>
|
|
|
|
|
{
|
|
|
|
|
if (i % 3 == 0 )
|
|
|
|
|
{
|
|
|
|
|
printf("---------------------\n");
|
|
|
|
|
}
|
|
|
|
|
for (int j = 0; j < 9; j++) //<2F><>
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|