Palindromic Password
InterviewTime limit3sMemory limit512 MB
For each six-digit number, print the closest six-digit palindrome, breaking ties by choosing the smaller one.
- Level
Easy3 of 10
- Topics
- Array, Brute force, Math
- Solved
- No attempts yet
Problem
The IT department at your school changed its password rules. A password is six-digit numbers joined by hyphens, and depends on the phase of the moon and the next day's weather forecast.
If every one of those six-digit numbers is a palindrome (it reads the same forwards and backwards), you only have to remember three-digit numbers. So you take a list of randomly generated six-digit numbers and replace each one with the six-digit palindrome closest to it.
Write a program that performs this replacement for you.
Input
The first line contains the count of six-digit numbers. ()
Each of the next lines contains one six-digit number. The number has no leading zero, so it is between and .
Output
For each number given in the input, print on its own line the six-digit palindrome closest to it. Closest means the absolute difference with the original number is the smallest. If two palindromes tie for the smallest difference, print the smaller one. The printed number must not have a leading zero either.