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 <stdio.h>
#include <map>
#include <algorithm>
#include <iostream>
#include <string>
#include <math.h>
using namespace std; int main(){
string a;
cin >> a;
if (a[] == '-'){
printf("-");
a.erase(, );
}
else if (a[] == '+'){
a.erase(, );
}
a.erase(, );
int pos_e;
pos_e = a.find('E');
string sub_str = a.substr(pos_e + , a.length() - pos_e - );
int flag = ;
if (sub_str[] == '-')flag = -;
a.erase(pos_e, + sub_str.length());
sub_str.erase(, );
while (!sub_str.empty() && sub_str[] == ''){
sub_str.erase(, );
}
int exp = ;
if (sub_str.empty())exp = ;
else{
for (int i = ; i < sub_str.length(); i++){
exp = exp * + sub_str[i] - '';
}
}
int extra = ;
if (flag == -){
for (int i = ; i < exp - ; i++){
a.insert(, "");
}
a.insert(,"0.");
}
else{
int l = a.length(); if (exp >= l - ){
for (int i = ; i < exp - l+;i++){
a.insert(a.length(),"");
} }
else{
a.insert( + exp, ".");
}
}
cout << a;
system("pause");
}

注意点:和B1024一样,就是分情况实现,字符串转数字,要记得字符串的find,erase,substr操作。

PAT A1073 Scientific Notation (20 分)——字符串转数字的更多相关文章

  1. PAT 甲级 1073 Scientific Notation (20 分) (根据科学计数法写出数)

    1073 Scientific Notation (20 分)   Scientific notation is the way that scientists easily handle very ...

  2. PAT Advanced 1073 Scientific Notation (20 分)

    Scientific notation is the way that scientists easily handle very large numbers or very small number ...

  3. PAT Basic 1024 科学计数法 (20 分) Advanced 1073 Scientific Notation (20 分)

    科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式 [+-][1-9].[0-9]+E[+-][0-9]+,即数字的整数部分只有 1 位,小数部分至少有 1 位,该数字及其指 ...

  4. PAT甲级——1073 Scientific Notation (20分)

    Scientific notation is the way that scientists easily handle very large numbers or very small number ...

  5. 【PAT甲级】1073 Scientific Notation (20 分)

    题意: 输入科学计数法输出它表示的数字. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> u ...

  6. PAT 1073 Scientific Notation

    1073 Scientific Notation (20 分)   Scientific notation is the way that scientists easily handle very ...

  7. PAT 1073 Scientific Notation[字符串处理][科学记数法]

    1073 Scientific Notation(20 分) Scientific notation is the way that scientists easily handle very lar ...

  8. PAT甲级——A1073 Scientific Notation

    Scientific notation is the way that scientists easily handle very large numbers or very small number ...

  9. 1073. Scientific Notation (20)

    题目如下: Scientific notation is the way that scientists easily handle very large numbers or very small ...

随机推荐

  1. 关于Unsupported major.minor version 52.0解决办法(再次回顾)

    对于web项目的配置问题,在很大程度上,tomcat的版本问题起到很大的决定性因素,例如以上问题:Unsupported major.minor version 52.0 表示stanford par ...

  2. css兼容问题(一)

    开头语:不用就忘,还是自己乖乖的记笔记吧! 正文开始:    (一)如果你的页面对IE7兼容没有问题,又不想大量修改现有代码,同时又能在IE8中正常使用,微软声称,开发商仅需要在目前兼容IE7的网站上 ...

  3. 试议常用Javascript 类库中 throttle 与 debounce 辅助函数的区别

    问题的引出 看过我前面两篇博客的童鞋可能会注意到都谈到了事件处理的优化问题. 在很多应用中,我们需要控制函数执行的频率, 例如 窗口的 resize,窗口的 scroll 等操作,事件触发的频率非常高 ...

  4. 【工具相关】Web-HTML特殊字符对照表

    特殊符号 命名实体 十进制编码 特殊符号 命名实体 十进制编码 特殊符号 命名实体 十进制编码 Α Α Α Β Β Β Γ Γ Γ Δ Δ Δ Ε Ε Ε Ζ Ζ Ζ Η Η Η Θ Θ Θ Ι Ι ...

  5. 【读书笔记】iOS-手势识别

    一,事件处理机制 事件是当用户手指触及屏幕,或地屏幕上滑动,或摇晃设备等时候,系统不断地把这些事件通过消息发送给应用程序对象.在iOS设备中能够捕获的事件有3种:触摸事件,移动事件和多媒体远程控制事件 ...

  6. 我的Java之旅 第六课 JAVA WEB 请求与响应

    一.有关URL编码    1.在URL的规范中定义了一些保留字符,如::  /  ?  & =  @  % 等,在URI中有它的作用.如果要在URI中包含这些字符,必须转码,即%字符后跟十六进 ...

  7. iOS动画-从UIView到Core Animation

    首先,介绍一下UIView相关的动画. UIView普通动画: [UIView beginAnimations: context:]; [UIView commitAnimations]; 动画属性设 ...

  8. Related concepts of testing

    根据是否知道源代码测试可以分为黑盒和白盒. 黑盒:功能测试. 白盒:知道源代码,要写测试代码. 根据测试的粒度. 方法测试: 单元测试: 集成测试: 系统测试: 根据测试的暴力程度. 压力测试:谷歌工 ...

  9. NoHttp封装--01

    NoHttpActivity public class NoHttpActivity extends Activity implements View.OnClickListener { privat ...

  10. JMeter—定时器(八)

    参考<全栈性能测试修炼宝典JMeter实战>第六章 JMeter 元件详解中第三节定时器 JMeter中的定时器一般用来设置延迟与同步.定时器的执行优先级高于取样器,在同一作用域下有多个定 ...