Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("hanoi.in");
- ofstream fout("hanoi.out");
- int n;
- unsigned long long nr;
- void towerOfHanoi(int n, char from_rod, char to_rod, char aux_rod)
- {
- if (n == 1)
- {
- fout<<from_rod<<"->"<<to_rod<<'\n';
- return;
- }
- towerOfHanoi(n-1, from_rod, aux_rod, to_rod);
- fout<<from_rod<<"->"<<to_rod<<'\n';
- towerOfHanoi(n-1, aux_rod, to_rod, from_rod);
- }
- int main()
- {
- fin>>n;
- nr=(1<<n)-1;
- fout<<nr<<'\n';
- towerOfHanoi(n, 'A', 'C', 'B');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement