PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4
Author: yash_daga
Tester: raysh07
Editorialist: iceknight1093
DIFFICULTY:
TBD
PREREQUISITES:
None
PROBLEM:
You pay a cab driver 100 dollars, but your trip’s cost is X dollars.
The cab driver can only pay you back with 10 dollar notes. How much will he return, if he never pays back more than he owes?
EXPLANATION:
Since the trip’s cost is X and you pay 100, the cab driver must repay (100 - X) dollars.
He only has 10's, so he’ll thus pay the largest multiple of 10 that doesn’t exceed (100 - X).
You can find this by either brute-force checking all multiple of 10 to find the largest valid one, or noting that you can simply take (100 - X) and subtract its last digit to get the answer.
TIME COMPLEXITY:
\mathcal{O}(1) per testcase.
CODE:
Editorialist's code (Python)
for _ in range(int(input())):
x = int(input())
x = 100 - x
print(x - x%10)