A12359 | Prefixes and Suffixes
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Ivan wants to play a game with you. He picked some string $s$ of length $n$ consisting only of lowercase Latin letters.
You don't know this string. Ivan has informed you about all its improper prefixes and suffixes (i.e. prefixes and suffixes of lengths from $1$ to $n-1$ ), but he didn't tell you which strings are prefixes and which are suffixes.
Ivan wants you to guess which of the given $2n-2$ strings are prefixes of the given string and which are suffixes. It may be impossible to guess the string Ivan picked (since multiple strings may give the same set of suffixes and prefixes), but Ivan will accept your answer if there is at least one string that is consistent with it. Let the game begin!
You don't know this string. Ivan has informed you about all its improper prefixes and suffixes (i.e. prefixes and suffixes of lengths from $1$ to $n-1$ ), but he didn't tell you which strings are prefixes and which are suffixes.
Ivan wants you to guess which of the given $2n-2$ strings are prefixes of the given string and which are suffixes. It may be impossible to guess the string Ivan picked (since multiple strings may give the same set of suffixes and prefixes), but Ivan will accept your answer if there is at least one string that is consistent with it. Let the game begin!
输入格式
The first line of the input contains one integer number $n$ ( $2 \le n \le 100$ ) — the length of the guessed string $s$ .
The next $2n-2$ lines are contain prefixes and suffixes, one per line. Each of them is the string of length from $1$ to $n-1$ consisting only of lowercase Latin letters. They can be given in arbitrary order.
It is guaranteed that there are exactly $2$ strings of each length from $1$ to $n-1$ . It is also guaranteed that these strings are prefixes and suffixes of some existing string of length $n$ .
The next $2n-2$ lines are contain prefixes and suffixes, one per line. Each of them is the string of length from $1$ to $n-1$ consisting only of lowercase Latin letters. They can be given in arbitrary order.
It is guaranteed that there are exactly $2$ strings of each length from $1$ to $n-1$ . It is also guaranteed that these strings are prefixes and suffixes of some existing string of length $n$ .
输出格式
Print one string of length $2n-2$ — the string consisting only of characters 'P' and 'S'. The number of characters 'P' should be equal to the number of characters 'S'. The $i$ -th character of this string should be 'P' if the $i$ -th of the input strings is the prefix and 'S' otherwise.
If there are several possible answers, you can print any.
If there are several possible answers, you can print any.
输入输出样例
输入 #1
5 ba a abab a aba baba ab aba
输出 #1
SPPSPSPS
输入 #2
3 a aa aa a
输出 #2
PPSS
输入 #3
2 a c
输出 #3
PS
The only string which Ivan can guess in the first example is "ababa".
The only string which Ivan can guess in the second example is "aaa". Answers "SPSP", "SSPP" and "PSPS" are also acceptable.
In the third example Ivan can guess the string "ac" or the string "ca". The answer "SP" is also acceptable.
The only string which Ivan can guess in the second example is "aaa". Answers "SPSP", "SSPP" and "PSPS" are also acceptable.
In the third example Ivan can guess the string "ac" or the string "ca". The answer "SP" is also acceptable.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted