Editorial for TLE '17 Contest 1 P1 - String Rounding

Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.

Submitting an official solution before solving the problem yourself is a bannable offence.

Author: ZQFMGB12

We can simply follow the instructions given in the problem description to round a number.

Use a loop from the rightmost character of the number to the leftmost character. If the current character is within a to m, then set it to a and break the loop. Otherwise, set the current character to a and check the next left character. If we are at the end, break from the loop and add a at the beginning of the number. If the next character is not z, then increment it by 1 and break. Otherwise, continue the loop.

Time Complexity: \mathcal{O}(|S|)


There are no comments at the moment.