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
看网上都是用 C++ 模拟,挂一个 py 代码,非常简洁:
s=input()
pos1=s.find('.')
pos2=s.find('E')
sgn1="" if s[0]=='+' else '-'
sgn2=s[pos2+1]
pre=s[1:pos1]
suf=s[pos1+1:pos2]
e=int(s[pos2+2:])
if sgn2=='-':if e>=len(pre):print(sgn1+'0.'+'0'*(e-len(pre))+pre+suf)else:print(sgn1+pre[:len(pre)-e]+'.'+pre[len(pre)-e:]+suf)
else:if e>=len(suf):print(sgn1+pre+suf+'0'*(e-len(suf)))else:print(sgn1+pre+suf[:e]+'.'+suf[e:])