3.10 PAT1024 乙级 python(第四个测试点错误 等后期修改)

科学计数法

x = list(input())
result = ''
eindex = 0
daxiao = 0
pindex = 0
nindex = 0
endnindex = 0
for i in range(len(x)):
    if x[i].isdigit() and eindex == 0 :
        nindex = i
    elif x[i] =='.':
        pindex = i
    elif x[i] == 'E':
        eindex = i
    elif x[i].isdigit() and eindex != 0 and endnindex == 0:
        endnindex = i
    elif (x[i] == '+' or x[i] == '-') and eindex != 0:
        if x[i] == '+':
            daxiao = 1
zhishu = int(''.join(x[endnindex:len(x)]))
if x[0] == '-':
    result = result + '-'
if zhishu ==0:
    result += ''.join(x[1:nindex+1])
else:
    if daxiao == 1:
        if nindex-2>int(x[-2:-1][0]+x[-1]):
            result = result+x[1]+ ''.join(x[3:zhishu+3])+'.'+''.join(x[zhishu+1:nindex+1])
        else:
            result = result+x[1]+''.join(x[3:nindex+1])+'0'*(zhishu-(nindex-2))
    else:
        result = result+'0.'+(zhishu-1)*'0'+x[1]+''.join(x[3:nindex+1])
print(result)

猜你喜欢

转载自blog.csdn.net/qq_39782006/article/details/88380674