题解 | #统计每个月兔子的总数#

统计每个月兔子的总数

http://www.nowcoder.com/practice/1221ec77125d4370833fd3ad5ba72395

#include<iostream>
using namespace std;

int main()
{
    int month[1024];
    int index = 0;
    while( cin>>month[index])
    {
         index ++;
    }
    for(int j = 0; j < index; j++)
    {
         int num =1;
        if(month[j] < 1)
        {
            cout << 0;
            return 0;
        }
        if(month[j] == 1 || month[j] == 2)
        {
            cout << 1;
            return 0;
        }
        int tmp = 1;
        for(int i = 2; i<month[j]; i++)
        {
            int x = num;
            num += tmp;
            tmp = x;
        }
        cout << num <<endl;
    }
    return 0;
}
全部评论

相关推荐

阿里控股很好,牛客也很客观
投递阿里巴巴控股集团等公司7个岗位 >
点赞 评论 收藏
转发
点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务