Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- ifstream fin("hanoi.in");
- ofstream fout("hanoi.out");
- void h(int n, char A, char B, char C)
- {
- if(n==1)
- fout<<A<<"->"<<C<<endl;
- else
- {
- h(n-1, A, C, B);
- h(1, A, B, C);
- h(n-1, B, A, C);
- }
- }
- int main()
- {
- int n, cnt=1;
- fin>>n;
- for(int i=0; i<n; i++)
- cnt*=2;
- fout<<cnt-1<<endl;
- h(n, 'A', 'B', 'C');
- return 0;
- }
Add Comment
Please, Sign In to add comment