You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
664 B
28 lines
664 B
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
|
|
//将n个圆盘从x柱子上借助y柱子移动到z柱子上
|
|
void move(int n, char x, char y, char z) {
|
|
if (n == 1)
|
|
printf("圆盘编号 %d :从 %c 移动到 %c\n", n, x, z);
|
|
else {
|
|
move(n - 1, x, y, z);
|
|
printf("圆盘编号 %d:从 %c 移动到 %c\n", n, x, z);
|
|
move(n - 1, y, x, z);
|
|
}
|
|
}
|
|
|
|
int main() {
|
|
int n;//n代表圆盘的个数
|
|
/*A,B,C分别代表三个柱子*/
|
|
char ch1 = 'A';
|
|
char ch2 = 'B';
|
|
char ch3 = 'C';
|
|
|
|
cout << "请输入圆盘的个数:" << endl;
|
|
cin >> n;
|
|
move(n, ch1, ch2, ch3);
|
|
return 0;
|
|
}
|