首页 > 其他 > 详细

输出带固定小数位数的浮点类型

时间:2020-03-05 00:39:29      阅读:77      评论:0      收藏:0      [点我收藏+]

一个题案例过不了,结果是因为,cout输出科学计数法了。

那么这样写就好了

#include<bits/stdc++.h>
#define N 105 
#define endl ‘\n‘ 
#define _for(i,a,b) for(int i=a;i<b;i++)
using namespace std;
typedef long long ll;
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n,len; int res = 0;
    cin>>n>>len;
    vector<int> a(n); 
    for( int & i : a) cin>>i; 
    sort(a.begin(),a.end()); 
    _for(i,0,n-1){ 
        if( a[i]==a[i+1] ) continue; 
        res = max(res,abs(a[i+1]-a[i]) ) ;
    }
    res = max( res,2*a[0] );
    res = max( res,2*(len-a[n-1]) );
    cout<<fixed<< setprecision(9) << res/2.0 <<endl;
    return 0;
} 

 

输出带固定小数位数的浮点类型

原文:https://www.cnblogs.com/SunChuangYu/p/12417027.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!