#abc288b. B - Qualification Contest
B - Qualification Contest
Score : points
问题描述
在一次竞赛中有 名参与者。排名第 位的参赛者昵称为 。
请按 字典序顺序 打印前 名参赛者的昵称。
什么是字典序顺序?
简而言之,字典序顺序就是词典中单词排列的顺序。作为正式描述,以下是一种对不重复字符串 和 进行排序的算法。
令 表示字符串 的第 个字符。若 在字典序上小于 ,我们写为 ;若 更大,则写为 。
- 计算 和 中较短者的长度,记为 。对于 ,检查 是否等于 。
- 若存在某个 使得 ,取最小这样的 值,记为 。比较 和 。若 字母表顺序上小于 ,则有 ;若 更大,则有 。
- 若不存在使 的 ,则比较 和 的长度。若 比 短,则有 ;若 更长,则有 。
综上所述,请按照上述字典序顺序规则,输出前 名参赛者的昵称。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There were participants in a contest. The participant ranked -th had the nickname .
Print the nicknames of the top participants in lexicographical order.
What is lexicographical order?
Simply put, the lexicographical order is the order of words in a dictionary. As a formal description, below is an algorithm to order distinct strings and .
Let denote the -th character of a string . We write if is lexicographically smaller than , and if is larger.
- Let be the length of the shorter of and . For , check whether equals .
- If there is an such that , let be the smallest such . Compare and . If is alphabetically smaller than , we get ; if is larger, we get .
- If there is no such that , compare the lengths of and . If is shorter than , we get ; if is longer, we get .
Constraints
- and are integers.
- is a string of length consisting of lowercase English letters.
- if .
Input
The input is given from Standard Input in the following format:
Output
Print the nicknames, separated by newlines.
Sample Input 1
5 3
abc
aaaaa
xyz
a
def
Sample Output 1
aaaaa
abc
xyz
This contest had five participants. The participants ranked first, second, third, fourth, and fifth had the nicknames abc
, aaaaa
, xyz
, a
, and def
, respectively.
The nicknames of the top three participants were abc
, aaaaa
, xyz
, so print these in lexicographical order: aaaaa
, abc
, xyz
.
Sample Input 2
4 4
z
zyx
zzz
rbg
Sample Output 2
rbg
z
zyx
zzz
Sample Input 3
3 1
abc
arc
agc
Sample Output 3
abc
update @ 2024/3/10 12:01:36