汉诺塔问题
#include<iostream> #include<algorithm> using namespace std; void move(char c1,char c2) { cout << "move: " << c1 << c2 << endl; } void hanoi(char a,char b,char c,int n) { if(n==1) move(a,c); else { hanoi(a,c,b,n-1); move(a,c); hanoi(b,a,c,n-1); } } int main(void) { int n; cin >> n; hanoi('a','b','c',n); return 0; }