WEICY123 @ 2024-05-23 21:37:52
double x; cin>>x; if(x==0){ cout<<x; } else cout<<floor(x); }
by lixuanxi @ 2024-05-23 21:42:27
完全不用你那么麻烦
by lixuanxi @ 2024-05-23 21:42:48
强制转换类型就好了
by lixuanxi @ 2024-05-23 21:42:58
@WEICY123
by Terrible @ 2024-05-23 21:44:59
向零舍入
double x;cin>>x;
cout<<(long long)(x);
洛谷环境中,对于 long long
范围内可以接受的浮点数 (long long)(x)
的实现是向零取整。
by lixuanxi @ 2024-05-23 21:45:44
本蒟蒻同意楼上观点
by Terrible @ 2024-05-23 21:49:24
当然如果不清楚这一点的话当然可以通过判断来避免,判断要明确很多:
向零舍入的含义是,正数向下舍入,负数向上舍入。
double x;cin>>x;
if(x>=0)cout<<floor(x);
else cout<<ceil(x);
by WEICY123 @ 2024-05-24 18:38:02
@lixuanxi @Terrible 已AC,感谢
by lixuanxi @ 2024-05-24 20:22:42
求关 @WEICY123