解题思路:
斐波那契
注意事项:
参考代码:
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int [] sum=new int[n]; int count=0; for (int i = 0; i < sum.length; i++) { sum[i]=sc.nextInt(); } for (int i = 0; i < sum.length; i++) { count=1; //如果上1层或2层则只有一种上法 if (sum[i]<3) { System.out.println(1); continue; } //从第三层开始,上第n层楼的方法为上他前两层楼方法的和 for (int j = 1; j <= sum[i]-2; j++) { count=count+j; } System.out.println(count); } } }
0.0分
1 人评分
P1001 (C语言代码)浏览:801 |
蛇行矩阵 (C语言代码)浏览:753 |
C语言训练-大、小写问题 (C语言代码)浏览:614 |
简单的for循环浏览:1410 |
wu-淘淘的名单 (C++代码)浏览:1339 |
简单的a+b (C语言代码)浏览:606 |
完数 (C语言代码)浏览:693 |
母牛的故事 (C语言代码)浏览:716 |
1113题解浏览:789 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:476 |