Love for 9
Practice
4.2 (4 votes)
Easy
Problem
59% Success 755 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Hardik likes the number 9, One of his friend gave him a number N, and want him to turn it into a multiple of 9. His friend gave him some restriction that he cannot add or remove digits, and he can only change one digit at a time. The only allowed operation is to increment or decrement a digit by one, and doing this takes exactly one second. Note that he cannot increase a digit 9 or decrease a digit 0, and the resulting number must not contain any leading zeroes unless N has a single digit. So Hardik has to find the minimum amount of time (in seconds) needed to accomplish this.

CONSTRAINT

  • 1≤T≤1000
  • 1≤N≤10^(10^5)
  • N will not contain leading zeroes.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
42 votes
Tags:
CombinatoricsAd-HocEasyMathematicsOpenApproved
Points:20
17 votes
Tags:
MathematicsBasic MathModular arithmeticMath
Points:20
979 votes
Tags:
Ad-HocEasyReadyMathematicsOpenApproved
Editorial

No editorial available for this problem.