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.
10-29/suiji.c

67 lines
1.3 KiB

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
void swap(int *a,int *b){//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int temp;
temp=*a;
*a=*b;
*b=temp;
}
void shuffle(int *array,int size){ //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int i;
int j;
srand(time(NULL));
for(i=size-1;i>0;i--){
j=rand()%(i+1);
swap(&array[i],&array[j]);
}
}
void fillBoard(int board[9][9])
{
int arr[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
int positions[9];//λ<><CEBB> <20><>0<EFBFBD><30>8
int i,j;
for (i=0;i<9;i++)
{
positions[i]=i;
}
//ÿ<><C3BF><EFBFBD><EFBFBD>
for (i=0;i<9;i+= 3)
{
shuffle(arr,9);//<2F><><EFBFBD><EFBFBD>0-9 <20><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
shuffle(positions,9);
for (j = 0; j < 3; j++)
{//ÿ<><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
board[i][positions[j]] = arr[j];
board[i+1][positions[j+3]] = arr[j+3];
board[i+2][positions[j+6]] = arr[j+6];
}
}
}
void print(int board[9][9]){//<2F><>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
printf("|-----------------------|\n");
int i=0,j=0,s=0,k=0;
for(i=0;i<9;++i){
for(j=0;j<9;j++){
while(j%3==0){
printf("| ");
break;
}
printf("%d ",board[i][j]);
}
printf("|\n");
while((i+1)%3==0){
printf("|-----------------------|\n");
break;
}
}
}
int main(){
int board[9][9]={0};//<2F><>ʼ<EFBFBD><CABC>
fillBoard(board);
print(board);
return 0;
}