Decimal Drift Simulator
Python
Hard
2 views
Problem Description
Read x and n. Repeat n times: x = round(x,2) + 0.1 (decimal rounding half up). Output final x with exactly 2 decimals.
Input Format
One line: x n.
Output Format
One number with 2 decimals.
Official Solution
import sys
from decimal import Decimal,ROUND_HALF_UP
p=sys.stdin.read().strip().split()
if not p: sys.exit(0)
x=Decimal(p[0])
n=int(p[1])
step=Decimal('0.1')
for _ in range(n):
x=x.quantize(Decimal('0.01'), rounding=ROUND_HALF_UP)+step
x=x.quantize(Decimal('0.01'), rounding=ROUND_HALF_UP)
sys.stdout.write(f'{x:.2f}')
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!