90分求助!

B2016 浮点数向零舍入

apzzzx @ 2024-08-15 10:00:37

#include<bits/stdc++.h>
using namespace std;
long double a;
int main(){
    cin>>a;
    if(a>=0){
        cout<<(long long)floor(a);
    }else{
        cout<<(long long)ceil(a);
    }
    if(a==0){
        cout<<0;
    }
    return 0;
}

by apzzzx @ 2024-08-15 10:01:49

第九个测试点没过


by zhizhenhuyuzhe @ 2024-08-15 10:03:19

#include<bits/stdc++.h>
using namespace std;
int main(){
    long long x;
    cin>>x;
    cout<<x;
}

逆天。。


by hanxiaofensheng @ 2024-08-15 10:07:07

@zhizhenhuyuzhe 我咋也是这么写的, 回答问题还要争分夺秒......


by zhizhenkanliyan @ 2024-08-15 10:07:17

@apzzzx 逆天

#include<iostream>
using namespace std;
int main(){
    long long x;
    cin>>x;
    cout<<x<<endl;
    return 0;
}

......


by apzzzx @ 2024-08-15 10:08:17

@zhizhenkanliyan ......


by August_Light @ 2024-08-15 10:16:35

@apzzzx a=0


by apzzzx @ 2024-08-15 11:20:47

@August_Light

if(a==0){
        cout<<0;
    }

是这个吗?


by August_Light @ 2024-08-15 11:43:22

@apzzzx

```cpp if(a>=0){ cout<<(long long)floor(a); } ``` 会被满足,于是输出 `0`。 但同时, ```cpp if(a==0){ cout<<0; } ``` 也会被满足,于是输出 `0`。 所以输入为 `0` 时,输出为 `00`,显然是不对的。去掉后面的特判就好了。

by apzzzx @ 2024-08-15 13:58:50

@August_Light

感谢 已经AC了


|