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

统计每个月兔子的总数

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

#include <iostream>
using namespace std;

int rabbit(int one,int two,int three,int n){
    int tem;
    while(n--){
        three = three + two;
        two = one;
        one = three;
    }
    return one+two+three;
}

int main() {
    int n;
    while (cin >> n) { 
        cout<<rabbit(1, 0, 0, n-1)<<endl;
    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务