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

统计每个月兔子的总数

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

全部评论

相关推荐

10-28 11:04
已编辑
美团_后端实习生(实习员工)
一个2人:我说几个点吧,你的实习经历写的让人觉得毫无含金量,你没有挖掘你需求里的 亮点, 让人觉得你不仅打杂还摆烂。然后你的简历太长了🤣你这个实习经历看完,估计没几个人愿意接着看下去, sdk, 索引这种东西单拎出来说太顶真了兄弟,好好优化下简历吧
点赞 评论 收藏
分享
点赞 评论 收藏
分享
美团 后端开发 总包n(15%是股票)
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务