*ハノイの塔 [#c68e3446] #geshi(cpp){{ // hanoi // Promblem // hanoi #include <iostream> #include <string> #define FROM "A" #define TO "B" #define WORK "C" using namespace std; unsigned int counter; void solve(int x, string from, string to, string work){ void solve(int x, std::string from, std::string to, std::string work){ static unsigned int counter = 0; if(x == 1){ cout << ++counter << ": " << from << " to " << to << endl; std::cout << ++counter << ": " << from << " to " << to << std::endl; }else{ solve(x-1, from, work, to); cout << ++counter << ": " << from << " to " << to << endl; std::cout << ++counter << ": " << from << " to " << to << std::endl; solve(x-1, work, to, from); } } int main() { const std::string FROM = "A"; const std::string TO = "B"; const std::string WORK = "C"; // Input the circle count int x; // Input the circle count cout << "Input x > "; cin >> x; std::cout << "Input x > "; std::cin >> x; counter = 0; solve(x, FROM, TO, WORK); return 0; } }}