100 atcoder#ABC219C. [ABC219C] Neo-lexicographic Ordering
[ABC219C] Neo-lexicographic Ordering
Score : points
Problem Statement
Takahashi, who governs the Kingdom of AtCoder, has decided to change the alphabetical order of English lowercase letters.
The new alphabetical order is represented by a string , which is a permutation of a
, b
, , z
. The -th character of would be the -th smallest English lowercase letter in the new order.
The kingdom has citizens, whose names are , where each consists of lowercase English letters. Sort these names lexicographically according to the alphabetical order decided by Takahashi.
What is the lexicographical order?
Simply speaking, the lexicographical order is the order in which words are listed in a dictionary. As a more formal definition, here is the algorithm to determine the lexicographical order between different strings and .
Below, let denote the -th character of . Also, if is lexicographically smaller than , we will denote that fact as ; if is lexicographically larger than , we will denote that fact as .
- Let be the smaller of the lengths of and . For each , we check whether and are the same.
- If there is an such that , let be the smallest such . Then, we compare and . If comes earlier than in alphabetical order, we determine that and quit; if comes later than , we determine that and quit.
- If there is no such that , we compare the lengths of and . If is shorter than , we determine that and quit; if is longer than , we determine that and quit.
Constraints
- is a permutation of
a
,b
, ,z
. - is an integer.
- consists of lowercase English letters.
Input
Input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the -th smallest name when the citizens' names are sorted according to the alphabetical order decided by Takahashi.
bacdefghijklmnopqrstuvwxzy
4
abx
bzz
bzy
caa
bzz
bzy
abx
caa
In the new alphabetical order set by Takahashi, b
is smaller than a
and z
is smaller than y
. Thus, sorting the citizens' names lexicographically would result in bzz
, bzy
, abx
, caa
in ascending order.
zyxwvutsrqponmlkjihgfedcba
5
a
ab
abc
ac
b
b
a
ac
ab
abc