- 汉诺塔问题
又是造福苍生的一天
- @ 2026-11-21 11:49:51
#include <bits/stdc++.h>
using namespace std;
void moveDisks(int n, char source, char dest, char temp)
{
if (n > 0)
{
moveDisks(n - 1, source, temp, dest);
cout << source <<"->" << n<< "->" << dest << endl;
moveDisks(n - 1, temp, dest, source);
}
}
int main()
{
int num;
char chara,charb,charc;
cin >> num >> chara >> charb >> charc;
moveDisks(num , chara , charb , charc);
return 0;
}
0 comments
No comments so far...
Information
- ID
- 685
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 4
- Tags
- (None)
- # Submissions
- 120
- Accepted
- 55
- Uploaded By