Languages
Time limit2sMemory limit1024 MB
Given names for digits 0 to 9, find for each number the digit in it whose name comes last in alphabetical order.
- Level
Easy2 of 10
- Topics
- String, Implementation
- Solved
- No attempts yet
Problem
Fedor decided to learn a new language and started by memorizing the names of the digits. To check what he has learned, he picks a number and finds the digit in it whose name comes last in alphabetical order. Fedor is not fully sure of his knowledge yet, so he needs a checker.
Word comes before word in alphabetical order if either is a prefix of , or the two words share their first few characters (possibly none) and the next character of comes before the corresponding character of in the alphabet.
Write a program that helps Fedor check his answers. A number is given. Find the digit in it whose name comes last in alphabetical order, compared with the names of the other digits. The digit names are given in the input file.
Input
The first line contains the names of the digits from to in the language Fedor is learning, separated by spaces. Each name is nonempty and consists of at most 50 lowercase Latin letters.
The second line contains (). The next lines each contain a number for which Fedor wants the answer (, with no leading zeros).
Output
On the -th line, print one word: the name of the digit that appears in and comes last in alphabetical order.