CF58D.Calendar
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
BerOilGasDiamondBank has branches in n cities, at that n is an even number. The bank management wants to publish a calendar with the names of all those cities written in two columns: the calendar should consist of exactly n / 2 lines of strictly equal length, each of which contains exactly two names and exactly one separator character between them. The name of every city should be used in the calendar exactly once. For historical reasons the symbol d is used as the separator of words in the calendar.
The BerOilGasDiamondBank management wants to show that all its branches are equally important to it, that's why the order of their appearance in the calendar should be following: if we "glue"(concatinate) all the n / 2 calendar lines (from top to bottom) to make a single line, then the lexicographically minimal line is obtained. No separator character will be used to separate calendar lines. For example, if the lines are "bertown!berville", "newberville!bera", then the resulting line is "bertown!bervillenewberville!bera". In some sense one has to find the lexicographically minimal calendar, where the comparison of calendars happens line by line.
Help BerOilGasDiamondBank and construct the required calendar.
BerOilGasDiamondBank 在 n 座城市设有分行,其中 n 为偶数。银行管理层希望发布一份日历,将所有这些城市的名称排成两列:该日历应恰好包含 n / 2 行,且每行长度严格相等;每行恰好包含两个城市名,并在它们之间恰好有一个分隔符字符。每个城市名在日历中必须且仅能出现一次。出于历史原因,日历中单词间的分隔符固定为符号 d。
BerOilGasDiamondBank 管理层希望表明其所有分行对其同等重要,因此日历中城市名的排列顺序需满足如下要求:若将全部 n / 2 行日历(从上到下)“拼接”(即连接)为单一行字符串(行与行之间不添加任何分隔符),则所得字符串在字典序意义上最小。例如,若各行分别为 "bertown!berville" 和 "newberville!bera",则拼接后结果为 "bertown!bervillenewberville!bera"。某种意义上,需找出字典序最小的日历,而日历之间的字典序比较是按行逐行进行的。
请帮助 BerOilGasDiamondBank 构造出满足上述要求的日历。
输入格式
The first line contains an integer n (1 ≤ n ≤ 104, n is even) which is the number of branches. Then follow n lines which are the names of the cities. All the names consist of lowercase Latin letters; their lengths are no less than 1 and no more than 10 symbols. The next line contains a single symbol d (d has an ASCII-code from 33 to 126 inclusively, excluding lowercase Latin letters) which is the separator between words in the calendar lines. It is guaranteed that the calendar is possible to be constructed and all the names are different.
第一行包含一个整数 n(1≤n≤104,且 n 为偶数),表示分支的数量。接下来的 n 行是城市名称。所有名称均由小写拉丁字母组成;其长度不少于 1 个字符,不多于 10 个字符。下一行包含一个单独的符号 d(d 的 ASCII 码在 33 到 126 之间(含端点),且 d 不是小写拉丁字母),该符号用作日历各行中单词之间的分隔符。保证日历可以被构造出来,且所有城市名称互不相同。
输出格式
Print n / 2 lines of similar length which are the required calendar. Every line should contain exactly two words and exactly one separator between them. If there are several solutions, print the lexicographically minimal one. The lexicographical comparison of lines is realized by the "<" operator in the modern programming languages.
输出 ⌊n/2⌋ 行长度相近的日历行。每行应恰好包含两个单词,且两个单词之间恰好有一个分隔符。若存在多种解,输出字典序最小的一个。行之间的字典序比较方式与现代编程语言中的 < 运算符一致。
输入输出样例
输入#1
4 b aa hg c .
输出#1
aa.b c.hg
输入#2
2 aa a !
输出#2
a!aa
输入#3
2 aa a |
输出#3
aa|a
输入解题思路,AI测评打分。不知道怎么写?