Thaphanoi
// Online C++ compiler to run C++ program online #include <iostream> using namespace std; void dichuyen(int sovien, int di, int den, int trunggian) { if (sovien == 1) { cout << "Move " << di << " to " << den; cout << endl; return; } dichuyen(sovien - 1, di, trunggian, den); dichuyen(1, di, den, trunggian); dichuyen(sovien-1, trunggian, den, di); } int main() { // Write C++ code here int n; cin >> n; dichuyen(n, 1, 3, 2); }
Leave a Comment