A7876 | Director
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
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 $2n$ 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.
输出格式
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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted