more tests
This commit is contained in:
parent
d0f8b3e0ad
commit
1bcff515b7
22 changed files with 191 additions and 58 deletions
20
test/function/hanoi.c
Normal file
20
test/function/hanoi.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
int printf(char* format, ...);
|
||||
|
||||
void move(char from_rod, char to_rod) {
|
||||
printf("%c --> %c\n", from_rod, to_rod);
|
||||
}
|
||||
|
||||
void hanoi(int n, char from_rod, char to_rod, char aux_rod) {
|
||||
if (n == 1) {
|
||||
move(from_rod, to_rod);
|
||||
return;
|
||||
}
|
||||
hanoi(n - 1, from_rod, aux_rod, to_rod);
|
||||
move(from_rod, to_rod);
|
||||
hanoi(n - 1, aux_rod, to_rod, from_rod);
|
||||
}
|
||||
|
||||
int main() {
|
||||
int n = 3;
|
||||
hanoi(n, 'A', 'C', 'B');
|
||||
}
|
8
test/function/hanoi.out
Normal file
8
test/function/hanoi.out
Normal file
|
@ -0,0 +1,8 @@
|
|||
A --> C
|
||||
A --> B
|
||||
C --> B
|
||||
A --> C
|
||||
B --> A
|
||||
B --> C
|
||||
A --> C
|
||||
0
|
32
test/function/queen.c
Normal file
32
test/function/queen.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
int printf(char* format, ...);
|
||||
int putchar(int ch);
|
||||
|
||||
int a[9];
|
||||
|
||||
int ok(int x, int y) {
|
||||
for (int i = 1; i <= x - 1; ++i) {
|
||||
if (a[i] == y || a[i] - i == y - x || a[i] + i == y + x) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void queen(int x) {
|
||||
if (x > 8) {
|
||||
a[0]++;
|
||||
return;
|
||||
}
|
||||
for (int y = 1; y <= 8; ++y) {
|
||||
if (ok(x, y)) {
|
||||
a[x] = y;
|
||||
queen(x + 1);
|
||||
a[x] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
queen(1);
|
||||
printf("%d\n", a[0]);
|
||||
}
|
2
test/function/queen.out
Normal file
2
test/function/queen.out
Normal file
|
@ -0,0 +1,2 @@
|
|||
92
|
||||
0
|
Loading…
Add table
Add a link
Reference in a new issue