#1 WA 80

P5705 【深基2.例7】数字反转

PBZ_CICN @ 2023-05-11 18:35:07

Wrong Answer.wrong answer Too long on line 1.

求助,谢谢!

A = float(input())

A =int(A * 10)

B_1 = A % 10
B_2 = int((A-B_1) / 10) % 10
B_3 = int((A - B_1 - B_2) / 100) % 10
B_4 = int(A/1000)

C = B_1 + 0.1 * B_2 + 0.01 * B_3 + 0.001 * B_4
print(C)

by Aqqqw @ 2023-05-11 19:04:03

浮点数精度问题,用字符串输出试试


by Aqqqw @ 2023-05-11 19:06:56

print(str(B_1) + '.' + str(B_2) + str(B_3) + str(B_4))


by PBZ_CICN @ 2023-05-12 20:32:14

@Purpled 谢谢!


|