Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- // Ханойские башни
- int free_plate(int from, int to){
- return 6 - from - to;
- }
- void Hanoi(int size, int from, int to) {
- if (size == 1) {
- std:: cout << "Move disk 1 from plate " << from << " to plate " << to << std:: endl;
- return;
- }
- int free = free_plate(from, to);
- Hanoi(size - 1, from, free);
- std:: cout << "Move disk " << size << " from plate " << from << " to plate " << to << std:: endl;
- Hanoi(size - 1, free, to);
- }
- int main() {
- int n;
- std:: cout << "Enter the number of disks: ";
- std:: cin >> n;
- Hanoi(n, 1, 3);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement