eolymp
bolt
Try our new interface for solving problems
Problems

Are We There Yet?

Are We There Yet?

A palindrome is a word or sentence that has the same sequence of letters and/or digits when it is read forward or backward; spaces, punctuation, and capitalization are usually ignored. For example, "\textbf{Aha! Mob Omaha!}" and the very short "\textbf{Lion Oil}" are palindromes. Consider a six-digit odometer in a car that displays the total number of miles the car has been driven; no digits are displayed for fractional miles. Also ignore leading non-significant zeros in the odometer reading, so that "\textbf{002345}" is considered the same as "\textbf{2345}". With these rules, some odometer readings, such as "\textbf{002332}" or "\textbf{056765}" are palindromes. Also note that some of these palindromic numbers have an even number of digits and others have an odd number of digits. Given the current odometer reading on a car, calculate the number of miles the car must be driven to cause the odometer to display a palindrome. Example: The current odometer reading is \textbf{005432}. The next odometer reading that will be a palindrome is \textbf{005445}, so the number of miles that must be driven is \textbf{13}. The problem: Write a program that reads an odometer reading and displays the number of miles to the next odometer reading that will be a palindrome, and that palindrome. \InputFile There will be an arbitrary number of odometer readings in the input, each given as a line containing \textbf{6} decimal digits and the end of line character. A line containing \textbf{-1} and the end of line character will follow the last odometer reading. \OutputFile For each odometer reading in the input, calculate the number of miles to the closest odometer reading that is a palindrome. Display the input case number (\textbf{1}, \textbf{2}, …), the number of miles that must be driven, and the corresponding palindromic odometer reading. Follow the format of the output shown below in the sample.
Time limit 1 second
Memory limit 64 MiB
Input example #1
005432
000012
100002
000005
-1
Output example #1
Case 1: 13 miles to 005445.
Case 2: 10 miles to 000022.
Case 3: 1099 miles to 101101.
Case 4: 0 miles to 000005.
Source ACM North Central North America Regional Programming Contest, November 12, 2011