PAT 1073 Scientific Notation
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=;
for(int i=;i < s.size();i++){
sum = sum*+(s[i]-'');
}
return sum;
} int main(){
string s;cin >> s;
if(s[] == '-')cout << "-";
s = s.substr(,s.size()-); int pose = ;
for(int i=;i < s.size();i++){
if(s[i] == 'E')pose=i;
}
string s1 = s.substr(,pose);
string s2 = s.substr(pose+,s.size()-pose-);
// cout << s1 << " " << s2 <<endl;
// cout << to_int(s2);
int cnt = to_int(s2); string temp="";
for(int i=;i<s1.size();i++){
if(s1[i]!='.')temp = temp+s1[i];
}
// cout << temp;
if(s[pose+] == '-'){
string head = "0.";
for(int i=;i < cnt-;i++) head = head+"";
head = head + temp;
cout << head;
}
else if(s[pose+] == '+'){
if(temp.size() > cnt){
for(int i=;i <= cnt;i++)cout << temp[i];
if(cnt != temp.size()-)cout << ".";
for(int i=cnt+;i < temp.size();i++)cout << temp[i];
}
else{
cout << temp;
for(int i=;i <= cnt-temp.size();i++)cout << "";
}
} return ;
}
_1AC
PAT 1073 Scientific Notation的更多相关文章
- PAT 1073 Scientific Notation[字符串处理][科学记数法]
1073 Scientific Notation(20 分) Scientific notation is the way that scientists easily handle very lar ...
- PAT 甲级 1073 Scientific Notation (20 分) (根据科学计数法写出数)
1073 Scientific Notation (20 分) Scientific notation is the way that scientists easily handle very ...
- 1073 Scientific Notation (20 分)
1073 Scientific Notation (20 分) Scientific notation is the way that scientists easily handle very la ...
- PAT Advanced 1073 Scientific Notation (20 分)
Scientific notation is the way that scientists easily handle very large numbers or very small number ...
- PAT Basic 1024 科学计数法 (20 分) Advanced 1073 Scientific Notation (20 分)
科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式 [+-][1-9].[0-9]+E[+-][0-9]+,即数字的整数部分只有 1 位,小数部分至少有 1 位,该数字及其指 ...
- PAT甲级——1073 Scientific Notation (20分)
Scientific notation is the way that scientists easily handle very large numbers or very small number ...
- 1073. Scientific Notation (20)
题目如下: Scientific notation is the way that scientists easily handle very large numbers or very small ...
- PAT A1073 Scientific Notation (20 分)——字符串转数字
Scientific notation is the way that scientists easily handle very large numbers or very small number ...
- PAT (Advanced Level) 1073. Scientific Notation (20)
简单模拟题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> # ...
随机推荐
- java+tomcat开发环境搭建
java+tomcat开发环境搭建 一.jdk环境变量设置 ...........这里省略n个字............. 二.tomcat环境变量设置 安装好tomcat后 1.新建环境变量: CA ...
- PHP调用接口用post方法传送json数据
1.核心代码: <?php require("helper.php"); header('content-type:text/html;charset=utf-8'); $k ...
- vue-cli脚手架
cnpm i vue-cli -g //npm 安装报错,原因不明,可能是我改过东西的原因,但是cnpm可以安装 命令行进入要新建的vue的目录执行 C:\Users\76912\Videos\v ...
- es6合并数组...
加了...和不加...是不一样,...会把原来数组拆开
- JAVA微信公众号网页开发 —— 用户授权获取openid
官方文档:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140842 HttpClientUtil.java packa ...
- 使用msf对tomcat测试
1.1 使用nmap命令对目标主机进行扫描.单击桌面空白处,右键菜单选择"在终端中打开". 1.2 在终端中输入命令"nmap –sV 192.168.1.3" ...
- python模块化学习(一)
import time #获取cpu的时间: #获取本地时间: #获取标准时间格式: #获取时间戳: #print(time.clock()) #这个在3即将被舍弃 print(time.proces ...
- [转载]ORACLE日期时间函数大全
ORACLE日期时间函数大全 TO_DATE格式(以时间:2007-11-02 13:45:25为例) Year: yy two digits 两位年 ...
- 常用python的标准库
1.itsdangerous # 加密签名的数据 2.re # 正则表达式 3.time # 时间模块 4.keyword # 查看关键字5.random # 随机6.uuid
- java 原码反码及补码 总结
参考: http://www.cnblogs.com/zhangziqiu/archive/2011/03/30/ComputerCode.html http://blog.csdn.net/lius ...