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. Python学习 :面向对象(一)

    面向对象 一.定义 面向对象:面向对象为类和对象之间的应用 class + 类名: #在类中的函数称作 “方法“ def + 方法名(self,arg): #方法中第一个参数必须是 self prin ...

  2. win下python环境搭建以及安装pip、django

    1. 安装python并配置 下载安装python,这里我下载的是python2.7,听说2.7比较好用 地址:https://www.python.org/downloads/source/ 记住你 ...

  3. 修改并编译golang源码

    最近为了做Hyperledger Fabric国密改造,涉及到了golang源码的改动.特将操作过程整理如下,以供参考: golang的源码安装其实比较简单,只需运行源码包中的脚本src/all.ba ...

  4. 详解LeetCode 137. Single Number II

    Given an array of integers, every element appears three times except for one, which appears exactly ...

  5. react work with angularjs together

    http://blog.500tech.com/using-reactjs-with-angularjs/ http://www.funnyant.com/reactjs-what-is-it/ ht ...

  6. 20155227 2016-2017-2 《Java程序设计》第二周学习总结

    20155227 2016-2017-2 <Java程序设计>第二周学习总结 教材学习内容总结 本周学习的第三章内容与以前学过的C语言有很多共通的地方,学习起来还是比较快的. 主要的内容有 ...

  7. ruby学习笔记(2)-chomp,chop的区别

    还没开始系统性的学习Ruby,最近在看metasploit框架的exploit会涉及到Ruby脚本,也就硬着头皮一遍查阅资料一遍做些笔记吧. Ruby字符串中存在chop和chomp的内置函数.我在h ...

  8. 成都Uber优步司机奖励政策(4月15日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  9. 变态的iis10

    IIS10发布网站不能使用.NET4.0需要重新注册在之前版本的系统中使用如下命令可以直接重新注册: 但是windowsServer2016(iis 10) 使用该命令 提示 版本不支持 C:\WIN ...

  10. equals和==方法比较(一)

    问题描述 今天在使用spotbugs代码走查时发现这样一个问题,两个Long类型的变量使用==判断数值是否相等,spotbugs提示这是一个很致命的错误,代码大概如下, Long l1=123l; L ...