#include <stdio.h>

void hanoi(int n, char from, char temp, char to) {
    // 终止条件：只有1个圆盘时，直接从源柱移到目标柱
    if (n == 1) {
        printf("%c -> %c\n", from, to);
        return;
    }

    // 步骤1：将n-1个圆盘从from移到temp（用to作为辅助）
    hanoi(n - 1, from, to, temp);

    // 步骤2：将第n个圆盘从from移到to
    printf("%c -> %c\n", from, to);

    // 步骤3：将n-1个圆盘从temp移到to（用from作为辅助）
    hanoi(n - 1, temp, from, to);
}

int main() {
    int n;
    printf("请输入汉诺塔的圆盘数量：");
    scanf("%d", &n);

    // 调用递归函数，初始柱子为A，辅助为B，目标为C
    hanoi(n, 'A', 'B', 'C');

    return 0;
}
