修改文件结构。
This commit is contained in:
55
POP/07/Optional05.c
Executable file
55
POP/07/Optional05.c
Executable file
@@ -0,0 +1,55 @@
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
int numbers[10] = { 0 };
|
||||
int cube[3][3] = { 0 };
|
||||
|
||||
void output() {
|
||||
int i = 0, j = 0;
|
||||
for (i = 0; i < 3; i++) {
|
||||
for (j = 0; j < 3; j++) {
|
||||
printf("%d", cube[i][j]);
|
||||
printf(" ");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void pickNext(int row, int col) {
|
||||
int i = 0;
|
||||
if (row == 2 && col == 2) {
|
||||
for (int i = 1; i <= 9; i++) {
|
||||
if (numbers[i] == false) {
|
||||
cube[2][2] = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((cube[0][0] + cube[0][1] + cube[0][2] == 15)
|
||||
&& (cube[1][0] + cube[1][1] + cube[1][2] == 15)
|
||||
&& (cube[0][0] + cube[1][0] + cube[2][0] == 15)
|
||||
&& (cube[0][1] + cube[1][1] + cube[2][1] == 15)
|
||||
&& (cube[0][0] + cube[1][1] + cube[2][2] == 15)
|
||||
&& (cube[0][2] + cube[1][1] + cube[2][0] == 15)) {
|
||||
output();
|
||||
}
|
||||
}
|
||||
for (i = 1; i <= 9; i++) {
|
||||
if (numbers[i] == false) {
|
||||
numbers[i] = true;
|
||||
cube[row][col] = i;
|
||||
if (col == 2) {
|
||||
pickNext(row + 1, 0);
|
||||
}
|
||||
else {
|
||||
pickNext(row, col + 1);
|
||||
}
|
||||
numbers[i] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
pickNext(0, 0);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user