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> # ...
随机推荐
- 16.2-uC/OS-III同步 (事件标志组)
事件标志组 1.当任务要与多个事件同步时可以使用事件标志.若其中的任意一个事件发生时任务被就绪, 叫做逻辑或(OR).若所有的事件都发生时任务被就绪,叫做逻辑与( AND). 2.用户可以创建任意个事 ...
- 在 vue 中使用 vieiwer 图片预览插件
https://blog.csdn.net/WestLonly/article/details/79801800?utm_source=blogxgwz0 首先,感谢原作者 官网链接 github地址 ...
- EF设计模式之code first
为了支持以设计为中心的开发流程,EF推出了以代码为中心的模式code first.我们称之为代码优先开发,代码优先的开发支持更加优美的开发流程,允许在不使用设计器或者定义一个XML映射文件的情况下进行 ...
- typescript 01 认识ts和ts的类型
看ITYING ts专辑(前三集总结) TypeScript 是 Javascript 的超级,遵循最新的 ES6.Es5 规范.TypeScript 扩展了 JavaScript 的语法.TypeS ...
- java socket编程实例代码
1.所谓socket通常也称作"套接字",用于描述IP地址和端口,是一个通信链的句柄.应用程序通常通过"套接字"向网络发出请求或者应答网络请求. 两性话题 两性 ...
- 正则表达式 re.findall 用法
正则 re.findall 的简单用法(返回string中所有与pattern相匹配的全部字串,返回形式为数组)语法: findall(pattern, string, flags=0) import ...
- Python基础(六)_全局变量声明、可变参数、关键字参数
1. global声明全局变量 #声明name这个变量为全局变量,只是写在函数里面 #写代码时,尽量不要用全局变量,会一直占用内存. ------->{'name':'abc','s ...
- JavaScript实现全屏显示
<!doctype html> <html> <head> <title>全屏显示</title> <meta charset=&qu ...
- PXC添加新节点
先拉数据,再启用节点,可以避免SST 拉数据 [root@pxc_node1_172.16.11.132 ~]# /usr/bin/innobackupex --defaults-file=/etc/ ...
- Win10问题
WIN10去除我的电脑上面的6个文件夹 把下面代码复制,保存到.reg中,然后执行即可(修改注册表文件.reg) Windows Registry Editor Version 5.00 ;如需还原去 ...