首页 > 其他 > 详细

1007: 童年生活二三事

时间:2014-10-02 14:55:33      阅读:251      评论:0      收藏:0      [点我收藏+]

台州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;
}


1007: 童年生活二三事

原文:http://blog.csdn.net/mirrors_beyourself/article/details/39736491

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!