• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
村雨sup
自己选的路,跪着也要走完 XD
博客园    首页    新随笔    联系   管理    订阅  订阅
PAT 1073 Scientific Notation
1073 Scientific Notation (20 分)
 

Scientific notation is the way that scientists easily handle very large numbers or very small numbers. The notation matches the regular expression [+-][1-9].[0-9]+E[+-][0-9]+ which means that the integer portion has exactly one digit, there is at least one digit in the fractional portion, and the number and its exponent's signs are always provided even when they are positive.

Now given a real number A in scientific notation, you are supposed to print A in the conventional notation while keeping all the significant figures.

Input Specification:

Each input contains one test case. For each case, there is one line containing the real number A in scientific notation. The number is no more than 9999 bytes in length and the exponent's absolute value is no more than 9999.

Output Specification:

For each test case, print in one line the input number A in the conventional notation, with all the significant figures kept, including trailing zeros.

Sample Input 1:

+1.23400E-03

Sample Output 1:

0.00123400

Sample Input 2:

-1.2E+10

Sample Output 2:

-12000000000
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;


int to_int(string s){
    int sum=0;
    for(int i=0;i < s.size();i++){
        sum = sum*10+(s[i]-'0');
    }
    return sum;
}



int main(){
    string s;cin >> s;
    if(s[0] == '-')cout << "-";
    s = s.substr(1,s.size()-1);

    int pose = 0;
    for(int i=0;i < s.size();i++){
        if(s[i] == 'E')pose=i;
    }
    string s1 = s.substr(0,pose);
    string s2 = s.substr(pose+2,s.size()-pose-2);
//    cout << s1 << " " << s2 <<endl;
//    cout << to_int(s2);
    int cnt = to_int(s2);


    string temp="";
    for(int i=0;i<s1.size();i++){
        if(s1[i]!='.')temp = temp+s1[i];
    }
//    cout << temp;
    if(s[pose+1] == '-'){
        string head = "0.";
        for(int i=0;i < cnt-1;i++) head = head+"0";
        head = head + temp;
        cout << head;
    }
    else if(s[pose+1] == '+'){
        if(temp.size() > cnt){
            for(int i=0;i <= cnt;i++)cout << temp[i];
            if(cnt != temp.size()-1)cout << ".";
            for(int i=cnt+1;i < temp.size();i++)cout << temp[i];
        }
        else{
            cout << temp;
            for(int i=0;i <= cnt-temp.size();i++)cout << "0";
        }
    }



    return 0;
}

_1AC

 
posted on 2019-04-26 16:12  村雨sup  阅读(122)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3