zoukankan      html  css  js  c++  java
  • 1007: 童年二三事

    台州acm:1007: 童年生活二三事

    Description

    Redraiment小时候走路喜欢蹦蹦跳跳,他最喜欢在楼梯上跳来跳去。
    但年幼的他一次仅仅能走上一阶或者一下子蹦上两阶。


    如今一共同拥有N阶台阶,请你计算一下Redraiment从第0阶到第N阶共同拥有几种走法。

    Input

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

    Output

    相应每一个输入包含一个输出。


    为redraiment到达第n阶不同走法的数量。

    Sample Input

    1
    2
    0

    Sample Output

    1
    2
    
    
    MyCode:
    #include <iostream>
    
    using namespace std;
    
    int main( void )
    {
    	int num;
    	int array[41 ]= { 0, 1, 2 };
    	
    	while(( cin>>num ), num!= 0 )
    	{
    		if( num== 1 || num== 2 )
    		{
    			cout<< array[ num ]<< endl;
    		}
    		else
    		{
    			int i;
    			
    			for( i= 3; i<= num; i++ )
    			{
    				array[ i ]= array[ i- 1 ]+array[ i- 2];
    			}
    			
    			cout<< array[ num ]<< endl;
    		}
    	}
    	
    	return 0;
    }


    版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 相关阅读:
    C# macro function via #define __FILE__ __LINE__ ___FUNCTION__ __DATE__ __TIME__
    3
    2月23号
    3月26
    impala故障
    2月3号日更
    HDFS某个节点的磁盘满了
    3月2
    mq集群
    3月3
  • 原文地址:https://www.cnblogs.com/blfshiye/p/4626555.html
Copyright © 2011-2022 走看看