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

统计每个月兔子的总数

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

#include <iostream>
using namespace std;

int main() {
    int n;
    int result=0;
    while (cin >> n) { // 注意 while 处理多个 case
      if(n==2 || n==1)
      {
            cout<<1;
      }
      int first=1,second=1,result=0;
      for(auto i=3;i<=n;i++)
      {
            result=first+second;
            first=second;
            second=result;
      }
      cout<<result;
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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