http://codeforces.com/contest/1092/problem/C

Ivan wants to play a game with you. He picked some string ss of length nn 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 11 to n−1n−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−22n−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!

Input

The first line of the input contains one integer number nn (2≤n≤1002≤n≤100) — the length of the guessed string ss.

The next 2n−22n−2 lines are contain prefixes and suffixes, one per line. Each of them is the string of length from 11 to n−1n−1 consisting only of lowercase Latin letters. They can be given in arbitrary order.

It is guaranteed that there are exactly 22 strings of each length from 11 to n−1n−1. It is also guaranteed that these strings are prefixes and suffixes of some existing string of length nn.

Output

Print one string of length 2n−22n−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 ii-th character of this string should be 'P' if the ii-th of the input strings is the prefix and 'S' otherwise.

If there are several possible answers, you can print any.

Examples
input

Copy
5
ba
a
abab
a
aba
baba
ab
aba
output

Copy
SPPSPSPS
input

Copy
3
a
aa
aa
a
output

Copy
PPSS
input

Copy
2
a
c
output

Copy
PS
Note

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.

代码:

#include <bits/stdc++.h>
using namespace std; int N;
vector<string> v;
vector<string> l1, l2;
string ans; int main() {
scanf("%d", &N);
int cnt = 0;
for(int i = 0; i < 2 * N - 2; i ++) {
string s;
cin >> s;
v.push_back(s);
if(s.size() == N - 1)
l1.push_back(s);
} string l = "";
for(int i = 0; i < v.size(); i ++)
if(l1[0].substr(1, N - 2) == l1[1].substr(0, N - 2) && v[i] == l1[0].substr(0, v[i].size()))
cnt ++; if(cnt >= N - 1) l = l1[0] + l1[1][N - 2];
else l = l1[1] + l1[0][N - 2]; map<int, int> mp;
for(int i = 0; i < v.size(); i ++) {
if(v[i] == l.substr(0, v[i].size()) && !mp[v[i].size()]) {
ans += "P";
mp[v[i].size()] ++;
}
else
ans += "S";
} cout << ans << endl;
return 0;
}

  两个小时。。。改的想吐 口区!

CodeForces Round #527 (Div3) C. Prefixes and Suffixes的更多相关文章

  1. CodeForces Round #527 (Div3) B. Teams Forming

    http://codeforces.com/contest/1092/problem/B There are nn students in a university. The number of st ...

  2. CodeForces Round #527 (Div3) D2. Great Vova Wall (Version 2)

    http://codeforces.com/contest/1092/problem/D2 Vova's family is building the Great Vova Wall (named b ...

  3. CodeForces Round #527 (Div3) D1. Great Vova Wall (Version 1)

    http://codeforces.com/contest/1092/problem/D1 Vova's family is building the Great Vova Wall (named b ...

  4. CodeForces Round #527 (Div3) A. Uniform String

    http://codeforces.com/contest/1092/problem/A You are given two integers nn and kk. Your task is to c ...

  5. Codeforces Round #527 (Div. 3) ABCDEF题解

    Codeforces Round #527 (Div. 3) 题解 题目总链接:https://codeforces.com/contest/1092 A. Uniform String 题意: 输入 ...

  6. 【赛时总结】◇赛时·V◇ Codeforces Round #486 Div3

    ◇赛时·V◇ Codeforces Round #486 Div3 又是一场历史悠久的比赛,老师拉着我回来考古了……为了不抢了后面一些同学的排名,我没有做A题 ◆ 题目&解析 [B题]Subs ...

  7. Codeforces Round #527 (Div. 3)

    一场div3... 由于不计rating,所以打的比较浪,zhy直接开了个小号来掉分,于是他AK做出来了许多神仙题,但是在每一个程序里都是这么写的: 但是..sbzhy每题交了两次,第一遍都是对的,结 ...

  8. Codeforces Round #527 (Div. 3) C. Prefixes and Suffixes

    题目链接 题意:给你一个长度n,还有2*n-2个字符串,长度相同的字符串一个数前缀一个是后缀,让你把每个串标一下是前缀还是后缀,输出任意解即可. 思路;因为不知道前缀还是后缀所以只能搜,但可以肯定的是 ...

  9. Codeforces Round #527 (Div. 3) C. Prefixes and Suffixes (思维,字符串)

    题意:给你某个字符串的\(n-1\)个前缀和\(n-1\)个后缀,保证每个所给的前缀后缀长度从\([1,n-1]\)都有,问你所给的子串是前缀还是后缀. 题解:这题最关键的是那两个长度为\(n-1\) ...

随机推荐

  1. 【Mac】安装 Homebrew 出错 Failed during: git fetch origin master:refs/remotes/origin/master --tags --force

    今天在 Mac 装 Homebrew 遇到了一个问题,在网上找了大量解决方案,做个总结. Mac 版本 High Sierra 10.13.6. 问题描述 在 Mac 终端输入了 Homebrew 官 ...

  2. Python3 urllib 爬取 花瓣网图片

    点我去我的github上看源码 **花瓣网是动态的,所以要抓包分析,,但我真的累的不行,不想写教程了,我源码里有注释

  3. Eclipse怎么恢复默认界面

    Eclipse里面将界面恢复到默认状态: 1.选择Eclipse的工具栏里面的“窗口(Window)”,找到“复位透视图(Reset Perspective)”选项: 2.单击“复位透视图(Reset ...

  4. 20155223 2006-2007-2 《Java程序设计》第二周学习总结

    20155223 2006-2007-2 <Java程序设计>第二周学习总结 第三章内容总结 3.1 类型 正如我所预料的情况一样:Java脱胎于C语言,就一定会留有和C语言相近或相同的语 ...

  5. Mysql优化分页

    背景: 库里面有张表,日增数据量百万条: 之前查询: SELECT * FROM `res_battery_data_history` LIMIT 1797000,10;

  6. RHCSA-考前准备

    1.考前准备 RHCSA classroom虚拟机和server虚拟机 将两台虚拟机切换到初始化快照 打开虚拟机电源,当出现提示时选择我已移动该虚拟机 系统密码: classroom: root As ...

  7. Redis实现之客户端

    客户端 Redis服务器是典型的一对多服务器程序:一个服务器可以与多个客户端建立网络连接,每个客户端可以向服务器发送命令请求,而服务器则接收并处理客户端发送的命令请求,并向客户端返回命令回复.通过使用 ...

  8. EF中一对多的自反关系设置

            对于一般的目录树,通常就是一对多的自反关系,一般会有一个PID,引用于这个ID,实体类代码类似于下: public partial class Catalog { public Cat ...

  9. python常用模块详解2

    序列化模块补充: 1.json格式的限制,json格式的key必须是字符串数据类型 2.json格式的字符串必须是"" 如果数字是key,那么dump之后会强转成字符串数据类型 i ...

  10. JVM知识(上)

    目录 什么是JVM? JVM的生命周期 JVM的体系结构 JVM的数据类型 java虚拟机被称为"虚拟",因为它是一个抽象的计算机定义的规范.要运行一个Java程序,需要一个抽象的 ...