A12119 | Refactoring
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Alice has written a program and now tries to improve its readability. One of the ways to improve readability is to give sensible names to the variables, so now Alice wants to rename some variables in her program. In her IDE there is a command called "massive refactoring", which can replace names of many variable in just one run. To use it, Alice needs to select two strings $s$ and $t$ and after that for each variable the following algorithm is performed: if the variable's name contains $s$ as a substring, then the first (and only first) occurrence of $s$ is replaced with $t$ . If the name doesn't contain $s$ , then this variable's name stays the same.
The list of variables is known and for each variable both the initial name and the name Alice wants this variable change to are known. Moreover, for each variable the lengths of the initial name and the target name are equal (otherwise the alignment of the code could become broken). You need to perform renaming of all variables in exactly one run of the massive refactoring command or determine that it is impossible.
The list of variables is known and for each variable both the initial name and the name Alice wants this variable change to are known. Moreover, for each variable the lengths of the initial name and the target name are equal (otherwise the alignment of the code could become broken). You need to perform renaming of all variables in exactly one run of the massive refactoring command or determine that it is impossible.
输入格式
The first line contains the only integer $n$ ( $1 \le n \le 3000$ ) — the number of variables in Alice's program.
The following $n$ lines contain the initial names of variables $w_1, w_2, \ldots, w_n$ , one per line. After that, $n$ more lines go, the $i$ -th of them contains the target name $w'_i$ for the $i$ -th variable. It is guaranteed that $1 \le |w_i| = |w'_i| \le 3000$ .
It is guaranteed that there is at least one variable having its target name different from the initial name. Both initial and target names consist of lowercase English letters only. For each variable the length of its initial name is equal to the length of its target name.
The following $n$ lines contain the initial names of variables $w_1, w_2, \ldots, w_n$ , one per line. After that, $n$ more lines go, the $i$ -th of them contains the target name $w'_i$ for the $i$ -th variable. It is guaranteed that $1 \le |w_i| = |w'_i| \le 3000$ .
It is guaranteed that there is at least one variable having its target name different from the initial name. Both initial and target names consist of lowercase English letters only. For each variable the length of its initial name is equal to the length of its target name.
输出格式
If it is impossible to rename all variables with one call of "massive refactoring", print "NO" (quotes for clarity).
Otherwise, on the first line print "YES" (quotes for clarity) and on the following lines print $s$ and $t$ ( $1 \le |s|, |t| \le 5000$ ), which should be used for replacement. Strings $s$ and $t$ should consist only of lowercase letters of English alphabet.
If there are multiple ways to perform a "massive refactoring", you can use any of them.
Otherwise, on the first line print "YES" (quotes for clarity) and on the following lines print $s$ and $t$ ( $1 \le |s|, |t| \le 5000$ ), which should be used for replacement. Strings $s$ and $t$ should consist only of lowercase letters of English alphabet.
If there are multiple ways to perform a "massive refactoring", you can use any of them.
输入输出样例
输入 #1
1 topforces codecoder
输出 #1
YES topforces codecoder
输入 #2
3 bab cac cdc bdb cdc cdc
输出 #2
YES a d
输入 #3
2 you shal not pass
输出 #3
NO
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted