7-5 汉诺塔问题 (10 分)
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
const int N = 1e6;
char st, ed, mid;
int n;
void dfs(int h, char a, char b, char c)
{
// cout << h << " " << a << ' ' << b << ' ' << c << endl;
if (h == 1) printf("%d: %c -> %c\n", h, a, b);
else {
dfs(h-1, a, c, b);
printf("%d: %c -> %c\n", h, a, b);
dfs(h-1, c, b, a);
}
}
int main()
{
cin >> n;
cin >> st >> ed >> mid;
dfs(n, st, ed, mid);
return 0;
}
7-5 汉诺塔问题 (10 分)
最新推荐文章于 2023-10-31 13:43:16 发布