将上题用C
```c #include <stdio.h> long long moves = 0; void hanoi(int n, char source, char target, char auxiliary) { if (n == 1) { printf("%c->1->%c\n", source, target); moves++; } else { hanoi(n - 1, source, auxiliary, target); printf("%c->%d->%c\n", source, n, target); moves++; hanoi(n - 1, auxiliary, target, source); } } int main() { int N; scanf("%d", &N); moves = 0; hanoi(N, 'a', 'c', 'b'); printf("%lld\n", moves); return 0; } ``` [2026-01-05 17:52:24 | AI问答 | 165点数解答]
相关提问