Blame view

P85288_en/S001-AC.cc 297 Bytes
Imanol-Mikel Barba Sabariego authored
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>

using namespace std;

void hanoi(int n, char a, char b, char c)
{
	if(n == 1)
	{
		cout << a << " => " << c << endl;
		return;
	}
	hanoi(n-1,a,c,b);
	cout << a << " => " << c << endl;
	hanoi(n-1,b,a,c);
}

int main()
{
	int n;
	cin >> n;
	hanoi(n,'A','B','C');
	return 0;
}