Good License Plates
InterviewTime limit1sMemory limit128 MB
For each license plate, compute a base-26 value from the three letters and compare it to the four-digit number, printing whether their difference is within 100.
- Level
Easy2 of 10
- Topics
- String, Implementation, Math
- Solved
- No attempts yet
Problem
An Alberta license plate has two parts, as in ABC-0123: three letters followed by four digits.
A license plate is good if the absolute difference between the value of its letter part and the value of its digit part is at most 100.
The value of the letter part is computed by treating the three letters like a base-26 number. A is 0, B is 1, ..., and Z is 25. For example, the value of ABC is 0 * 26^2 + 1 * 26 + 2 = 28. Therefore, ABC-0123 is good because |28 - 123| <= 100.
Given several license plates, write a program that determines whether each one is good.
Input
The first line contains the number of license plates N. (1 <= N <= 100)
Each of the next N lines contains a license plate in the format LLL-DDDD. Each L is an uppercase English letter, and each D is a digit.
Output
For each license plate, print nice if it is good, or not nice otherwise, one result per line.