cswork / OA打开练习工作台

AmazonOA #130

Custom Sort String

估计简单可在线判题

考点(AI 标注)字符串原地数组

The alphabet gives the order of distinct characters from smallest to largest. Sort all strings lexicographically by this order; a shorter prefix comes first, and identical strings keep all their copies. The standard I/O uses - to represent the empty string, and - is not part of the allowed alphabet.

输入格式

The first line contains order, the second line contains n, followed by n strings (an empty string is written as -). order consists of uppercase and lowercase letters and digits, 1≤|order|≤62, 1≤n≤100000, and the total length of the original strings is ≤1000000.

输出格式

Output the n strings in sorted order, using - for the empty string and keeping duplicates.

样例 1

输入:

9AacB
7
BBBBa
BBBB9
B9ca
Aa999
B9A
B
B9A

输出:

Aa999 B B9A B9A B9ca BBBB9 BBBBa

样例 2

输入:

yYaAbBl
6
Yay
yaY
lyab
lyab
b
bay

输出:

yaY Yay b bay lyab lyab

样例 3

输入:

ba
5
-
a
b
ba
-

输出:

- - b ba a

样例说明

Example 1: the order is Aa999, B, B9A, B9A, B9ca, BBBB9, BBBBa; the source's BBB89 is a typo that altered a character. Example 2: yaY, Yay, b, bay, lyab, lyab; the duplicate lyab must not be changed to lyaB. Example 3: the two empty strings come first, followed by b, ba, a, and each empty string is output as -.