Repeated Rounding
InterviewTime limit1sMemory limit128 MB
Round each integer repeatedly at increasing place values (ones, tens, hundreds, ...) using round-half-up until the value no longer exceeds the current threshold.
- Level
Medium4 of 10
- Topics
- Math, Implementation, Simulation
- Solved
- No attempts yet
Problem
You are given an integer . Round it repeatedly according to the following rules.
- If is greater than , round at the ones place, i.e. change it to the nearest multiple of .
- If the result is greater than , round at the tens place, i.e. change it to the nearest multiple of .
- If the result is greater than , round at the hundreds place.
- Continue this way: while the rounded result is greater than the next threshold (), move one place higher and round again.
Rounding is round-half-up: if the part being dropped is at least half of the place value, round up; otherwise round down (for the ones place, a ones digit of or more rounds up). When you can no longer round (the current value is at most the current threshold), that value is the final result.
Input
The first line contains the number of test cases . Each of the following lines contains one integer to be rounded. ()
Output
For each test case, print the result of rounding the given integer by the rules above, one per line.