#15131: 好怪。避開0.995和0.495就AC了


willson318 (willson)

學校 : 不指定學校
編號 : 81391
來源 : [163.24.49.56]
最後登入時間 :
2024-05-22 14:25:07
d561. 被秒殺的四捨五入 -- jack1 | From: [114.47.199.132] | 發表日期 : 2018-09-15 16:33

#coding:UTF-8

import sys
import math
def calc(num):
if (num <0):
sign ="-"
else:
sign =""
if(-1<num<1):
anum = int(abs(num)*1000)
if( anum % 10 >=5):
bnum = int(abs(num)*100+1)
else:
bnum = int(abs(num)*100)
if (anum ==495):
return(sign+"0.49")
elif (anum == 995):
if (num >0 ):
return(sign+"0.99")
else:
return (sign +"1.00")
elif(bnum>=100):
return(sign+"1.00")
elif(bnum>=10):
return(sign + "0." +str(bnum))
elif(bnum>=1):
return(sign + "0.0" + str(bnum))
else:
return("0.00")


else:
tnum = int(abs(num)*1000+5)
ltnum = len (str(tnum))
stnum = str(tnum)

if (num>=0):
return (stnum[:ltnum-3]+"."+stnum[-3:-1])
else:
return ("-"+stnum[:ltnum-3]+"."+stnum[-3:-1])



sIN=sys.stdin.readline()
while(sIN != ""):
sIN = sIN.replace("\r","").replace("\n","")
print(calc(float(sIN)))
sIN=sys.stdin.readline()

 
ZeroJudge Forum