Skip to content

Instantly share code, notes, and snippets.

@yao2030
Created June 21, 2014 02:02
Show Gist options
  • Save yao2030/ccd716fed6c1e81b8f41 to your computer and use it in GitHub Desktop.
Save yao2030/ccd716fed6c1e81b8f41 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
void Hanoi(int n, char src, char mid, char dest) {
if (n == 1) {
cout << src << " -> " << dest << endl;
return;
}
Hanoi(n-1, src, dest, mid);
cout << src << " -> " << dest << endl;
Hanoi(n - 1, mid, src, dest);
}
int main(void) {
int n;
cin >> n;
Hanoi(n, 'A', 'B', 'C');
return 0;
}
@yao2030
Copy link
Author

yao2030 commented Jun 21, 2014

闲着。。。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment