Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void _HaNoiTower(int n, string nguon, string tg, string dich);
- int main() {
- int n;
- cout << "Nhap so dia n = ";
- cin >> n;
- _HaNoiTower(n,"a", "b", "c");
- return 0;
- }
- void _HaNoiTower(int n, string nguon, string tg, string dich) {
- if (n == 1) cout << "\nDi chuyen dia "<<n<<" tu cot "<<nguon<<" sang cot "<< dich;
- else {
- _HaNoiTower(n-1,nguon, dich,tg);
- cout << "\nDi chuyen dia "<< n <<" tu cot "<< nguon <<" sang cot "<< dich;
- _HaNoiTower(n-1,tg, nguon,dich);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement