102881: [AtCoder]ABC288 B - Qualification Contest

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:4 Solved:0

Description

Score : $200$ points

Problem Statement

There were $N$ participants in a contest. The participant ranked $i$-th had the nickname $S_i$.
Print the nicknames of the top $K$ 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 $S$ and $T$.

Let $S_i$ denote the $i$-th character of a string $S$. We write $S \lt T$ if $S$ is lexicographically smaller than $T$, and $S \gt T$ if $S$ is larger.

  1. Let $L$ be the length of the shorter of $S$ and $T$. For $i=1,2,\dots,L$, check whether $S_i$ equals $T_i$.
  2. If there is an $i$ such that $S_i \neq T_i$, let $j$ be the smallest such $i$. Compare $S_j$ and $T_j$. If $S_j$ is alphabetically smaller than $T_j$, we get $S \lt T$; if $S_j$ is larger, we get $S \gt T$.
  3. If there is no $i$ such that $S_i \neq T_i$, compare the lengths of $S$ and $T$. If $S$ is shorter than $T$, we get $S \lt T$; if $S$ is longer, we get $S \gt T$.

Constraints

  • $1 \leq K \leq N \leq 100$
  • $K$ and $N$ are integers.
  • $S_i$ is a string of length $10$ consisting of lowercase English letters.
  • $S_i \neq S_j$ if $i \neq j$.

Input

The input is given from Standard Input in the following format:

$N$ $K$
$S_1$
$S_2$
$\vdots$
$S_N$

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

Input

题意翻译

给出 $N$ 个字符串 $S_i$,按字典序升序排序,输出前 $K$ 个。 - $1 \le K \le N \le 100$ - $S_i$ 仅包含英文小写字母,长度不超过 $10$

Output

得分:200分

问题描述

在一个竞赛中有$N$名参与者。第$i$名参与者的昵称为$S_i$。
字典序打印出前$K$名参与者的昵称。

什么是字典序?

简单来说,字典序就是字典中单词的顺序。作为一种正式的描述,以下是用于对不同的字符串$S$和$T$进行排序的算法。

让$S_i$表示字符串$S$的第$i$个字符。如果$S$在字典序上小于$T$,我们写$S \lt T$;如果$S$在字典序上大于$T$,我们写$S \gt T$。

  1. 让$L$表示$S$和$T$中较短的那个的长度。 对于$i=1,2,\dots,L$,检查$S_i$是否等于$T_i$。
  2. 如果存在一个$i$使得$S_i \neq T_i$,让$j$为这样的最小的$i$。比较$S_j$和$T_j$。如果$S_j$在字母顺序上小于$T_j$,我们得到$S \lt T$;如果$S_j$较大,我们得到$S \gt T$。
  3. 如果不存在一个$i$使得$S_i \neq T_i$,比较$S$和$T$的长度。如果$S$较短,我们得到$S \lt T$;如果$S$较长,我们得到$S \gt T$。

限制条件

  • $1 \leq K \leq N \leq 100$
  • $K$和$N$为整数。
  • $S_i$是一个长度为$10$的仅包含小写英文字母的字符串。
  • 如果$i \neq j$,则$S_i \neq S_j$。

输入

输入从标准输入按以下格式给出:

$N$ $K$
$S_1$
$S_2$
$\vdots$
$S_N$

输出

以换行符分隔打印昵称。


样例输入1

5 3
abc
aaaaa
xyz
a
def

样例输出1

aaaaa
abc
xyz

这个竞赛有五名参与者。排名前五的参与者昵称分别为abcaaaaaxyzadef

排名前三的参与者昵称为abcaaaaaxyz,因此按字典序打印:aaaaaabcxyz


样例输入2

4 4
z
zyx
zzz
rbg

样例输出2

rbg
z
zyx
zzz

样例输入3

3 1
abc
arc
agc

样例输出3

abc

加入题单

上一题 下一题 算法标签: