美文网首页
童年生活二三事

童年生活二三事

作者: Co_zy | 来源:发表于2018-07-20 22:38 被阅读0次

    童年生活二三事

    运行时限: 1000 ms 单次运行时限: 1000 ms 内存限制: 64 MB
    总提交: 2190次 通过: 674次

    题目描述

    Redraiment小时候走路喜欢蹦蹦跳跳,他最喜欢在楼梯上跳来跳去。
    但年幼的他一次只能走上一阶或者一下子蹦上两阶。
    现在一共有N阶台阶,请你计算一下Redraiment从第0阶到第N阶共有几种走法。

    程序输入说明

    输入包括多组数据。
    每组数据包括一行:N(1≤N≤40)。
    输入以0结束。

    程序输出说明

    对应每个输入包括一个输出。
    为redraiment到达第n阶不同走法的数量。

    程序输入样例

    可见格式 带空格和换行符的格式 带空格和换行符的格式说明

    1
    2
    0
    

    程序输出样例

    Original Transformed 带空格和换行符的格式说明

    1
    2
    

    提示 : 斐波那契数列

    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
        int n;
        int i;
        int a[100];
        int j = 0;
        int t1=1;
        int t2=1;
        int next;
        a[j++] = t1;
        for(i=0; i<40; i++)
        {
            next = t1 + t2;
            a[j++] = next;
            t1 = t2;
            t2 = next;
        }
        while(~scanf("%d",&n) && n!=0)
        {
            printf("%d\n",a[n-1]);
        }
        return 0;
    }
    

    相关文章

      网友评论

          本文标题:童年生活二三事

          本文链接:https://www.haomeiwen.com/subject/lgkcmftx.html