parent
							
								
									d372cf7f2d
								
							
						
					
					
						commit
						941808740b
					
				| @ -1,72 +0,0 @@ | |||||||
| #include <stdio.h> |  | ||||||
| #include <stdlib.h> |  | ||||||
| #include <time.h> |  | ||||||
| int board[9][9] = {0}, f[9] = {0}; |  | ||||||
| void f1() |  | ||||||
| { |  | ||||||
|     printf("|"); |  | ||||||
|     for (int i = 0; i < 23; i++) |  | ||||||
|     { |  | ||||||
|         printf("-"); |  | ||||||
|     } |  | ||||||
|     printf("|\n"); |  | ||||||
| } |  | ||||||
| void operate() |  | ||||||
| { |  | ||||||
|     for (int i = 0; i < 9; i++) |  | ||||||
|     { |  | ||||||
|         if (i % 3 == 0) |  | ||||||
|         { |  | ||||||
|             f1(); |  | ||||||
|         } |  | ||||||
|         printf("| "); |  | ||||||
|         for (int j = 0; j < 9; j++) |  | ||||||
|         { |  | ||||||
|             if (j % 3 == 0 && j) |  | ||||||
|             { |  | ||||||
|                 printf("| "); |  | ||||||
|             } |  | ||||||
|             printf("%d ", board[i][j]); |  | ||||||
|         } |  | ||||||
|         printf("|\n"); |  | ||||||
|     } |  | ||||||
|     f1(); |  | ||||||
| } |  | ||||||
| void random(int n) |  | ||||||
| { |  | ||||||
|     int k = 9; |  | ||||||
|     while (k) |  | ||||||
|     { |  | ||||||
|         int i = rand() % 3, j =rand() % 9; |  | ||||||
|         i += (n - 1) * 3; |  | ||||||
|         if (f[i] == 0) |  | ||||||
|         { |  | ||||||
|             if (board[i][j] == 0) |  | ||||||
|             { |  | ||||||
|                 board[i][j] = k; |  | ||||||
|                 k--; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         int cnt = 0; |  | ||||||
|         for (int m = 0; m < 9; m++) |  | ||||||
|         { |  | ||||||
|             if (board[i][m]) |  | ||||||
|             { |  | ||||||
|                 cnt++; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         if (cnt == 3) |  | ||||||
|         { |  | ||||||
|             f[i] = 1; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| int main() |  | ||||||
| { |  | ||||||
|     printf("Ëæ»ú¾ØÕóΪ£º\n"); |  | ||||||
|     srand(time(NULL)); |  | ||||||
|     random(1); |  | ||||||
|     random(2); |  | ||||||
|     random(3); |  | ||||||
|     operate(); |  | ||||||
| } |  | ||||||
					Loading…
					
					
				
		Reference in new issue