|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
|
|
void generateMatrix(int matrix[9][9]) {
|
|
|
|
|
srand(time(0)); // ʹ<>õ<EFBFBD>ǰʱ<C7B0><CAB1><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
int i,j;
|
|
|
|
|
for (i = 0; i < 9; i++) {
|
|
|
|
|
for (j = 0; j < 9; j++) {
|
|
|
|
|
matrix[i][j] = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ÿ<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
int row;
|
|
|
|
|
for (row = 0; row < 9; row++) {
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>1-9<><39><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
int nums[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
|
|
|
|
|
for (i = 0; i < 9; i++) {
|
|
|
|
|
int j = rand() % (i + 1);
|
|
|
|
|
int temp = nums[i];
|
|
|
|
|
nums[i] = nums[j];
|
|
|
|
|
nums[j] = temp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
for ( i = 0; i < 3; i++) {
|
|
|
|
|
matrix[row][i] = nums[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ÿ<EFBFBD>е<EFBFBD>˳<EFBFBD><CBB3>
|
|
|
|
|
for (row = 0; row < 9; row++) {
|
|
|
|
|
for ( i = 0; i < 9; i++) {
|
|
|
|
|
int j = rand() % 9;
|
|
|
|
|
int temp = matrix[row][i];
|
|
|
|
|
matrix[row][i] = matrix[row][j];
|
|
|
|
|
matrix[row][j] = temp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void printMatrix(int matrix[9][9]) {int i,j;
|
|
|
|
|
for (i = 0; i < 9; i++) {
|
|
|
|
|
for (j = 0; j < 9; j++) {
|
|
|
|
|
printf("%d ", matrix[i][j]);
|
|
|
|
|
}
|
|
|
|
|
printf("\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
int matrix[9][9];
|
|
|
|
|
|
|
|
|
|
generateMatrix(matrix);
|
|
|
|
|
printMatrix(matrix);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|