链家第二题求找错,10%,明明接受了多组数据

#include <iostream>
using namespace std;

int main() {
    int n;
    while (cin >> n){
        if (n <= 3) {
            cout << 0<<endl;
            continue;
        }
        int fst = 1, scd = 2, ct = 2;
        int cur = fst + scd;
        while (cur <= n)
        {
            ++ct;
            fst = scd;
            scd = cur;
            cur = fst + scd;
        }
        cout << n - ct<<endl;
    }
}

全部评论
作者:riverding 链接:https://www.nowcoder.com/discuss/72602?type=0&order=0&pos=11&page=1 来源:牛客网 #include <iostream>  using namespace std; int main() {     int i,n;     int count=0;     int a=2;     int b=3;     while (cin>>n) {         for(i=4;i<=n;i++){             if(i<a+b){                 count++;             }             else{                 a=b;                 b=i;             }         }         cout<<count<<endl;         count=0;     a=2;     b=3;     }     return 0; }
点赞 回复
分享
发布于 2018-04-08 21:18
最后一个数到n的没计算,我一开始也是这样10%
点赞 回复
分享
发布于 2018-04-08 21:37
联想
校招火热招聘中
官网直投

相关推荐

点赞 评论 收藏
转发
点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务