CF45E.Director
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Vasya is a born Berland film director, he is currently working on a new blockbuster, "The Unexpected". Vasya knows from his own experience how important it is to choose the main characters' names and surnames wisely. He made up a list of n names and n surnames that he wants to use. Vasya haven't decided yet how to call characters, so he is free to match any name to any surname. Now he has to make the list of all the main characters in the following format: "_Name_1 _Surname_1, _Name_2 _Surname_2, ..., Name__n Surname__n", i.e. all the name-surname pairs should be separated by exactly one comma and exactly one space, and the name should be separated from the surname by exactly one space. First of all Vasya wants to maximize the number of the pairs, in which the name and the surname start from one letter. If there are several such variants, Vasya wants to get the lexicographically minimal one. Help him.
An answer will be verified a line in the format as is shown above, including the needed commas and spaces. It's the lexicographical minimality of such a line that needs to be ensured. The output line shouldn't end with a space or with a comma.
瓦西娅是一位天生的贝尔兰电影导演,他目前正在制作一部新大片——《出乎意料》。瓦西娅凭自身经验深知,为主角精心挑选名字和姓氏至关重要。他已列出 n 个名字和 n 个姓氏供选用。目前瓦西娅尚未决定如何为角色命名,因此他可以自由地将任意名字与任意姓氏配对。现在,他需要按如下格式生成所有主角的名单:“_Name_1 _Surname_1, _Name_2 _Surname_2, ..., Name__n Surname__n”,即:所有“名字-姓氏”对之间必须恰好用一个逗号加一个空格分隔,且每个名字与其对应姓氏之间也必须恰好用一个空格分隔。
首先,瓦西娅希望最大化名字与姓氏首字母相同的配对数量;若存在多种方案达到该最大值,则他希望从中选出字典序最小的方案。请帮助他完成这一任务。
答案需严格按上述格式输出(包括所需的逗号与空格)。此处所指的“字典序最小”,是指最终输出的整行字符串的字典序最小。输出行末尾不得有空格或逗号。
输入格式
The first input line contains number n (1 ≤ n ≤ 100) — the number of names and surnames. Then follow n lines — the list of names. Then follow n lines — the list of surnames. No two from those 2_n_ strings match. Every name and surname is a non-empty string consisting of no more than 10 Latin letters. It is guaranteed that the first letter is uppercase and the rest are lowercase.
第一行输入包含一个数字 n(1≤n≤100)—— 表示姓名与姓氏的总对数。接下来是 n 行——姓名列表。再接下来是 n 行——姓氏列表。这 2n 个字符串中任意两个均不相同。每个姓名和姓氏均为非空字符串,且仅由至多 10 个拉丁字母组成。保证每个字符串的首字母为大写,其余字母均为小写。
输出格式
The output data consist of a single line — the needed list. Note that one should follow closely the output data format!
输出数据由一行组成——即所需列表。请注意,必须严格遵循输出数据格式!
输入输出样例
输入#1
4 Ann Anna Sabrina John Petrov Ivanova Stoltz Abacaba
输出#1
Ann Abacaba, Anna Ivanova, John Petrov, Sabrina Stoltz
输入#2
4 Aa Ab Ac Ba Ad Ae Bb Bc
输出#2
Aa Ad, Ab Ae, Ac Bb, Ba Bc
输入解题思路,AI测评打分。不知道怎么写?