forked from p8lxtapfy/matrix
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1001 B
56 lines
1001 B
#include<stdio.h>
|
|
#include<time.h>
|
|
#include<stdlib.h>
|
|
|
|
void matrixOutput(int matrixArr[9][9])
|
|
{
|
|
for (int i = 0; i < 9; i++)
|
|
{
|
|
for (int j = 0; j < 9; j++)
|
|
{
|
|
printf("%d", matrixArr[i][j]);
|
|
if (j != 8)
|
|
printf(" ");
|
|
}
|
|
if (i != 8)
|
|
printf("\n");
|
|
}
|
|
}
|
|
|
|
void matrixRandomInit(int matrixArr[9][9]){
|
|
int map[9] = {1,2,3,4,5,6,7,8,9};
|
|
int mp;
|
|
srand(time(NULL));
|
|
for(int i=0;i<9;i++){
|
|
for(int j=0;j<9;j++){
|
|
matrixArr[i][j] = 0;
|
|
}
|
|
}
|
|
for(int i=0;i<9;i++){
|
|
if(i%3==0){
|
|
mp=0;
|
|
for(int j=0;j<8;j++){
|
|
int n = i+rand()%(8-i);
|
|
int tmp = map[i];
|
|
map[i] = map[n];
|
|
map[n]=tmp;
|
|
}
|
|
}
|
|
int k=0;
|
|
while(k<3){
|
|
int tmpP = rand()%9;
|
|
if(matrixArr[i][tmpP]==0){
|
|
matrixArr[i][tmpP] = map[mp++];
|
|
k++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
int main(){
|
|
int board[9][9];
|
|
matrixRandomInit(board);
|
|
matrixOutput(board);
|
|
return 0;
|
|
}
|