Created
June 21, 2014 02:02
-
-
Save yao2030/ccd716fed6c1e81b8f41 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
闲着。。。