汉诺塔的移动
#include <iostream> #include <cstdio> using namespace std; void mov(int n,char f,char t) { printf("Move disk %d from %c to %c ",n,f,t); } void Han(int n, char A, char B, char C) { if(n == 1) { mov(n, A, C); return ; } Han(n - 1, A, C, B); mov(n, A, C); Han(n - 1, B, A, C); } int main() { int n; cin>>n; Han(n,'A','B','C'); return 0; }