main
m7wzyfpis 1 year ago
parent 90bbf09f2d
commit 60f179e4bb

55
2.cpp

@ -0,0 +1,55 @@
#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;
}
Loading…
Cancel
Save