超级楼梯

Problem Description
有一楼梯共M级,刚开始时你在第一级,若每次只能跨上一级或二级,要走上第M级,共有多少种走法?
 
Input
输入数据首先包含一个整数N,表示测试实例的个数,然后是N行数据,每行包含一个整数M(1<=M<=40),表示楼梯的级数。
 
Output
对于每个测试实例,请输出不同走法的数量
 
Sample Input
2
2
3
 
Sample Output
1
2
 
 1 #include <stdio.h> 
 2  
 3 int main(){
 4     int T;
 5     int number;
 6     int a;
 7     int b;
 8     int result;
 9     int i;
10     
11     scanf("%d",&T);
12     
13     while(T--){
14         scanf("%d",&number);
15         
16         if(number==1){
17             printf("0\n");
18             continue;
19         }
20             
21         else if(number==2){
22             printf("1\n");
23             continue;
24         }
25             
26         else if(number==3){
27             printf("2\n");
28             continue;
29         }
30         
31         a=1;
32         b=2;
33         for(i=1;i<=number-3;i++){
34             result=a+b;
35             a=b;
36             b=result;
37         }
38         
39         printf("%d\n",result);
40     }
41         
42         
43     return 0;
44 }

 

 

 

posted @ 2014-10-28 21:26  zqxLonely  阅读(206)  评论(0编辑  收藏  举报