#abc219c. C - Neo-lexicographic Ordering
C - Neo-lexicographic Ordering
Score : points
问题描述
Takahashi,治理AtCoder王国的人,已决定改变英语小写字母的字母顺序。
新的字母顺序由字符串表示,该字符串是a
, b
, , z
的一个排列。的第个字符()将是新顺序中第小的英文字母。
王国中有位公民,其名字分别为,其中每个 由小写英文字母组成。
按照Takahashi决定的字母顺序,对这些名字进行字典序排序。
什么是字典序?
简单来说,字典序就是词典中单词排列的顺序。更正式地讲,以下是确定不同字符串和之间的字典序的算法。
以下,用表示字符串的第个字符。此外,如果在字典序上小于,我们记作;如果在字典序上大于,我们记作。
- 让为和长度中较小的那个。对于每个,检查和是否相同。
- 如果存在某个使得,令为最小的这样的。然后比较和。若在字母顺序上早于,则确定并停止比较;若晚于,则确定并停止比较。
- 如果不存在满足的,则比较和的长度。若比短,则确定并停止比较;若比长,则确定并停止比较。
按照Takahashi决定的新字母顺序,请按字典序对这位公民的名字进行排序。
以上为通义千问 qwen-max 翻译,仅供参考。
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.
Sample Input 1
bacdefghijklmnopqrstuvwxzy
4
abx
bzz
bzy
caa
Sample Output 1
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.
Sample Input 2
zyxwvutsrqponmlkjihgfedcba
5
a
ab
abc
ac
b
Sample Output 2
b
a
ac
ab
abc
update @ 2024/3/10 09:41:18