解题思路:列出前几项,发现字符串满足s[i]=s[i-2]+s[i-1],所以很容易用递归写出结果。
#include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const int N = 2000; string a[20]; void print_(int x){ if(x>1){ print_(x-2); print_(x-1); } else cout<<a[x]; } int main() { int n; a[0]="0";a[1]="1"; scanf("%d",&n); print_(n); }
0.0分
1 人评分
【数组的距离】 (C语言代码)浏览:606 |
C语言程序设计教程(第三版)课后习题10.7 (C语言代码)浏览:525 |
C语言训练-求s=a+aa+aaa+aaaa+aa...a的值 (C语言代码)浏览:1031 |
字符串对比 (C语言代码)浏览:1401 |
C语言程序设计教程(第三版)课后习题6.9 (C语言代码)浏览:536 |
WU-蓝桥杯算法提高VIP-勾股数 (C++代码)浏览:1593 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:470 |
WU-判定字符位置 (C++代码)浏览:1400 |
C语言程序设计教程(第三版)课后习题6.1 (C语言代码)浏览:698 |
C语言程序设计教程(第三版)课后习题8.7 (C语言代码)浏览:594 |