博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PAT甲级——A1073 Scientific Notation
阅读量:4541 次
发布时间:2019-06-08

本文共 2135 字,大约阅读时间需要 7 分钟。

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
1 #include 
2 #include
3 using namespace std; 4 int main() 5 { 6 string str, f1, num1, num2, f2, num3, res = ""; 7 cin >> str; 8 int nDot, E, Exp = 0; 9 f1 = str[0];10 nDot = str.find('.');11 num1 = str[nDot - 1];//第一位数字12 E = str.find('E');13 num2.assign(str.begin() + nDot + 1, str.begin() + E);//小数点后面的数字14 f2 = str[E + 1];15 num3.assign(str.begin() + E + 2, str.end());//指数16 for (int i = 0; i < num3.length(); ++i)//计算指数17 Exp = Exp * 10 + num3[i] - '0';18 if (f1 == "-")19 res += "-";20 if (f2 == "-")21 {22 res += "0.";23 res.insert(res.end(), Exp - 1, '0');//中间插入024 }25 else if (f2 == "+")26 {27 if (num2.length() <= Exp)//小数位不足,则直接末尾加0;28 num2.insert(num2.end(), Exp - num2.length(), '0');29 else//小数位多余幂次,则小数点后移30 num2.insert(num2.begin() + Exp, 1, '.');31 }32 res += num1 + num2;33 cout << res << endl;34 return 0;35 }

 

转载于:https://www.cnblogs.com/zzw1024/p/11313511.html

你可能感兴趣的文章
用数据告诉你关于手机app的15个有趣事实
查看>>
BBC英语-adverbs of frequency
查看>>
python中的List,Tuple,Set,Dictionary
查看>>
JavaWeb 学习007-4个页面,5条sql语句(添加、查看、修改、删除)2016-12-2
查看>>
用JavaScript 来将数字转换成字符。
查看>>
扩展欧几里得算法
查看>>
java中的包装类
查看>>
采用多种算法,模拟摇奖:从1-36中随机抽出8个不重复的数字
查看>>
sp2.1 Practical aspects of Deep Learning
查看>>
java中的缓存
查看>>
2、文件夹
查看>>
DLL_Vs_CLL
查看>>
MakeFile
查看>>
AVAST 4.8
查看>>
6.1.1 web前端介绍
查看>>
jquery实现当前页面编辑
查看>>
初识rt-thread
查看>>
微服务架构下介质管理规范
查看>>
关于AutoCAD 2014的securityload…
查看>>
BM和KMP字符串匹配算法学习
查看>>