PATA 1073. Scientific Notation (20)
来源:互联网 发布:淘宝怎么绕过实拍保护 编辑:程序博客网 时间:2024/05/24 07:17
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-03Sample Output 1:
0.00123400Sample Input 2:
-1.2E+10Sample Output 2:
-12000000000代码如下:
#include<iostream>#include<deque>#include<string>#include<iterator>#include<sstream>using namespace std;void convert(string&);int main(){#ifdef ONLINE_JUDGE#else freopen("D:\\in.txt", "r", stdin); freopen("D:\\out.txt", "w", stdout);#endif string line; while(cin >> line) convert(line); return 0;}void convert(string& line){ string expstr(line,line.find('E') + 1); string num=line.substr(1,line.find('E')-1); long long exp; stringstream os; os << expstr; os >> exp; deque<char> coll; for (int i = 0; i < num.size(); i++) coll.push_back(num[i]); if (exp>0) { if (coll.size() - 2 <= exp) { int t = coll.size(); for (int i = 0; i < exp -t + 2; i++) coll.push_back('0'); coll.erase(coll.begin() + 1); } else { coll.insert(coll.begin() + 2 + exp, '.'); coll.erase(coll.begin() + 1); } } else if (exp<0) { coll.erase(coll.begin() + 1); for (int i = 0; i < abs(exp) - 1; i++) coll.push_front('0'); coll.push_front('.'); coll.push_front('0'); } if (line[0] == '-') coll.push_front('-'); for (deque<char>::iterator it = coll.begin(); it != coll.end(); it++) { cout << (*it); } cout << endl;}
- PATA 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- JSP中动态INCLUDE与静态INCLUDE的区别?
- 指出下面程序的运行结果:
- 写一个Singleton模式的例子
- ASP.NET 状态的传递和保持
- 简单的背包问题(入门)HDU2602 HDU2546 HDU1864
- PATA 1073. Scientific Notation (20)
- J2EE是什么?
- java线程管理利器:java.util.current的用法举例
- QT模态对话框及非模态对话框学习
- 点滴的学习快乐——CorelDraw 学习笔记 (1)
- 体会插入迭代器
- Thinking in BigDate(七)大数据技术核心之NoSql(一)
- hdu-4524- 郑厂长系列故事——逃离迷宫
- xmlHttp.status 和xmlhttp.readyState状态值