#include<iostream> using namespace std; void move(char a, char b){ cout << a << "->" << b << endl; } void hanoi(int n, char a, char b, char c){ if (n == 1) move(a, b);//直接由a到b else{ hanoi(n - 1, a, c, b);//把上面n-1个由a到c借助b move(a, b); hanoi(n - 1, c, b, a); } } int main(){ int n; cin >> n; char a = 'a', b = 'b', c = 'c'; hanoi(n, a, b, c);//把这n个由a到b借助c } 递归求解斐波那契数列 //输出第n项 #include<iostream> using namespace std; int Fib(int n){ if (n == 1) return 1; if (n == 2) return 1; else{ return Fib(n - 1) + Fib(n - 2); } } int main(){ int n; cin >> n; cout<<Fib(n); } //输出前n项 #include<iostream> using namespace std; int Fib(int n){ if (n == 1) return 1; if (n == 2) return 1; else{ return Fib(n - 1) + Fib(n - 2); } } int main(){ int n; cin >> n; for (int i = 1; i <= n; i++){ cout << Fib(i) << '\t'; } }