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

统计每个月兔子的总数

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

#include <stdio.h>
#include <math.h>
int main() {
    int n = 0;
    unsigned int m1Num = 1;
    unsigned int m2Num = 0;
    unsigned int m3Num = 0;
    unsigned int mnNum = 0;
    
    unsigned int m1Num_ = 1;
    unsigned int m2Num_ = 0;
    unsigned int m3Num_ = 0;
    unsigned int mnNum_ = 0;
    scanf("%d",&n);

    for(int i = 0; i < n; i++)
    {
        if(0 == i){
            m2Num_ = 0;
            m3Num_ = 0;
            m1Num_ = 1;
            mnNum_ = 0;
        }else if(1 == i){
            m2Num_ = 1;
            m3Num_ = 0;
            m1Num_ = 0;
            mnNum_ = 0;            
        }
        else{
            m2Num_ = m1Num;
            m3Num_ = m2Num;
            mnNum_ += m3Num;
            m1Num_ = m2Num + m3Num + mnNum;
        }

        m1Num = m1Num_;
        m2Num = m2Num_;
        m3Num = m3Num_;
        mnNum = mnNum_;
    }

    printf("%ld",(m1Num+m2Num+m3Num+mnNum));
    return 0;
}

全部评论

相关推荐

挣K存W养DOG:他真的很中意你,为什么不回他
点赞 评论 收藏
分享
三年之期已到我的offer快到碗里来:9硕都比不上9本
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务