浙江大学PAT_甲级_1073. Scientific Notation (20)
2015-08-18 16:52
387 查看
题目链接:点击打开链接
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:
Sample Output 1:
Sample Input 2:
Sample Output 2:
我的C++程序:
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
我的C++程序:
#include<iostream> #include<string> #include<sstream> using namespace std; int stringToint(const string &S)//利用stringstream完成string到int的转换 { stringstream ss; int result; ss << S; ss >> result; return result; } int main() { string s, number; int exp; cin >> s; char sign = s[0];//符号位,正负号 int LocE = s.find('E');//找到E的位置 number = s[1]; number =number+s.substr(3, LocE - 3);//得到数字部分内容 exp = stringToint(s.substr(LocE + 1)); if (sign == '-') { cout << "-"; } //三种可能的情况 if (exp<0)//前面加0 { cout << "0."; for (int i = 0; i < -exp - 1; i++) { cout << '0'; } cout << number; } else if (exp >= number.length() - 1)//后面加0,没小数点 { cout << number; for (int i = 0; i < exp - number.length() + 1; i++) { cout << '0'; } } else //小数点在中间 { cout << number.substr(0, exp + 1); cout << "."; cout << number.substr(exp + 1); } //system("pause"); return 0; }
相关文章推荐
- BZOJ1037
- 最小生成树~kruskal算法
- 使用 Fluent API 配置/映射属性和类型
- POJ 2376 Cleaning Shifts
- Arithmetic Sequence
- EBS环境提交新请求默认是"单一请求"
- Eclipse 打开报错Java was Started but Returned Exit Code=13
- msi 中断的写tlp包在哪里产生?
- 四种常见的 POST 提交数据方式
- excel中将一张表中数据拆分成多个工作表,按部门不相同的拆分成单个工作表,且单个工作表名及为部门
- 希尔排序
- 求最大连续bit数
- CAD教程-AL对其命令
- poj 2251 Dungeon Master 3维bfs(水水)
- 20150818 ELK(L)conf的学习
- Mac下MAMP中vhost的配置
- 待机异常篇
- iOS iOS8注册通知
- 封装connect/c++连接mysql
- 怎么进入 BAT 的研发部门?