From e37a8c4e4369d28f268790ffe4ad0a5806cc4659 Mon Sep 17 00:00:00 2001 From: prim85cto <2926098536@stu.xjtu.edu.cn> Date: Fri, 8 Nov 2024 17:45:14 +0800 Subject: [PATCH] ADD file via upload --- T2.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 T2.cpp diff --git a/T2.cpp b/T2.cpp new file mode 100644 index 0000000..f99c62a --- /dev/null +++ b/T2.cpp @@ -0,0 +1,41 @@ +#include +#include +#include + +void print_matrix(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() { + srand(time(NULL)); + int matrix[9][9] = {0}; + int i,j; + for (i = 0; i < 9; i += 3) { + int nums[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; + int flag1[9] = {0}; + int flag2[9] = {0}; + for(j=0;j<9;j++){ + int t,p; + re1: t=rand()%9; + if(flag1[t]==1){ + goto re1;} + re2: p=rand()%9; + if(flag2[p]==1){ + goto re2; + } + matrix[i+j/3][p]=nums[t]; + flag1[t]=1; + flag2[p]=1; + + } + } + + print_matrix(matrix); + return 0; +}