题解 | 特殊的科学计数法

特殊的科学计数法

https://www.nowcoder.com/practice/ca0962879d3b40d8bb598fb9a905ac7a

#include<bits/stdc++.h>
#include <string>
using namespace std;
#define int long long
#define x first
#define y second
#define space ' '
#define endl '\n'
#define pb push_back
#define all(x) x.begin(),x.end()

#define debug(x) x<<' '
typedef pair<int,int> PII;

const int N=2e5+10;
const int INF=0x3f3f3f3f3f3f3f3fLL;
const int inf=0x3f3f3f3f3f3f3f3fLL;
const int mod=1e9+7;
const int MOD=998244353;

int n,m,k,q;

void solve(){
    string s;
    cin>>s;
    if(s.size()<3){
        cout<<s[0]<<'.'<<s[1]<<"*10^"<<1;
        return ;
    }
    string ss=s.substr(0,3);
     int exp=s.size()-1;
     if(ss[2]-'0'>=5){
        int ans=(s[0]-'0')*10+(s[1]-'0')+1;
        string sss=to_string(ans);
        int expp=sss.size()-1;
         cout<<sss[0]<<"."<<sss[1]<<"*10^"<<exp+expp-1;
        
     }
     else{
         cout<<ss[0]<<"."<<ss[1]<<"*10^"<<exp;
     }
  
}

signed main(){
    // double start=(double)clock()/CLOCKS_PER_SEC;
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout<<fixed<<setprecision(3);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    // double end=(double)clock()/CLOCKS_PER_SEC;
    // cout<<endl<<"time="<<end-start<<endl;
    return 0;
}

全部评论
四舍五入就两种情况,我们只需要对第三个字符判断是否要舍去或者入,再对前两个字符操作就行。注意999这种情况
点赞 回复 分享
发布于 01-31 14:43 河南

相关推荐

评论
点赞
收藏
分享

创作者周榜

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