1073. Scientific Notation
2015-12-01 19:24
344 查看
1073. Scientific Notation (20)
时间限制100 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
HOU, Qiming
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 file 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<stdlib.h> #include<string> #include<iostream> #include<algorithm> #include<math.h> using namespace std; int main() { freopen("F://Temp/input.txt", "r", stdin); string input; cin>>input; string ans = ""; string str1, str2; //处理input字符串 int pos = 0; while(input[pos] != 'E') pos ++; str1 = input.substr(0, pos); str2 = input.substr(pos+1, input.size()-pos-1); int flag = 0;//+ or - if(input[pos + 1] == '-') flag = -1; else if(input[pos + 1] == '+') flag = 1; int bit1 = pos - 2; int bit2 = abs(atoi(str2.c_str())); ans += input[0]; if(flag == 1) { if(bit1 <= bit2 + 1) { for(int i = 1; i < str1.size(); i ++) { if(str1[i] != '.') ans += str1[i]; } for(int i = 0; i < bit2 + 1 - bit1; i ++) ans += '0'; } else if(bit1 > bit2 + 1) { ans += str1[1]; for(int i = 0; i < bit2; i ++) ans += str1[i + 3]; ans += '.'; for(int i = bit2 + 3; i < str1.size(); i ++) ans += str1[i]; } } else if(flag == -1) { ans += "0."; for(int i = 0; i < bit2 - 1; i ++) ans += '0'; for(int i = 0; i < str1.size(); i ++) if(str1[i + 1] != '.') ans += str1[i + 1]; } if(ans[0] == '+') ans = ans.substr(1); cout<<ans<<endl; return 0; }
[/code]
相关文章推荐
- 进程调度之FCFS,SJF,HRRN
- c009: 图的概念
- 前端开发-学习资料库
- 蓝桥杯OJ刷题日记——10-基础练习 十进制转十六进制
- FFmpeg工具使用总结
- java实现线程安全的单利模式
- 重载(Overload)和重写(Override)的区别。重载的方法能否根据返回类型进行区分?
- leetcode中MoveZeroes问题1ms→0ms
- ping和ssh设置中遇到的问题——hadoop 集群配置
- ping和ssh设置中遇到的问题——hadoop 集群配置
- qt_简易记事本_6
- PCB电路板板厂生产流程介绍
- Ugly Number
- java自带线程池和队列详细讲解
- 微信公众号网页授权 当scope为snsapi userinfo时出现空白页面
- Lightoj --1294
- ios UINavigationController
- BZOJ2302: [HAOI2011]Problem c
- html5自动定位
- 关于Android中RSA数字签名的理解及使用