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列表的通用操作

    #'+'和'*'#+可以将两个列表拼接为一个列表my_list = [1,2,3]+[4,5,6]#*可以将列表重复指定的次数my_list = [1,2,3]*5 print(my_list) #创 ...

  2. node.js之express中app.use

    express中app.use 用法: app.use([path,] function [, function…]) 一.app.use() 在express中是怎么工作的 app.use在expr ...

  3. Dart 语言了解

    Dart 语言了解 概念 当您了解Dart语言时,请记住以下事实和概念: 您可以放在变量中的所有内容都是一个对象,每个对象都是一个类的实例.偶数,函数和 null对象.所有对象都从Object类继承. ...

  4. 20155203 2016-2017-3 《Java程序设计》第4周学习总结

    20155203 2016-2017-3 <Java程序设计>第4周学习总结 教材学习内容总结 1.父类和子类类似于集合和元素,不同的地方是子类可以拓展(extends)父类之外的方法. ...

  5. 20155204 2016-2017-2 《Java程序设计》第2周学习总结

    20155204 2016-2017-2 <Java程序设计>第2周学习总结 教材学习内容总结 本章主要学习了Java语言的基础语法,基本同C语言逻辑相通,比较着学不算难理解,包括了一些简 ...

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

    20155328 2006-2007-2 <Java程序设计>第2周学习总结 教材学习内容总结 基本类型: 整数:short整数(占2字节).int整数(占4字节).long整数(占8字节 ...

  7. SupperSocket深入浅出(二)

    如果还没有看SuperStock深入浅出(一) ,请先看 这一章,主要说下命令是如果运行的.刚开始的时候会发现拷别人的代码命令是可以运行的,在修改的过程中突然发现命令无效了? 这里什么原因?,我先把代 ...

  8. Java泛型理解

    Java泛型提供了编译时类型安全检测机制,该机制允许程序员在编译时检测到非法的类型.当需要使用某一种算法时,又无法具体算法的数据类型,或者想指定类型值的上限或下限,那么这时就需要Java泛型来大显身手 ...

  9. Android手机测试-ddms&monitor-抓crash,log

    1.安装adb offline解决办法: 原因就是android 4.2以上的版本过高,sdk的adb驱动不匹配,需要升级.我原本的adb是1.0.29,升级为1.0.31,问题就解决了. 2.安装s ...

  10. 423. Valid Parentheses【LintCode java】

    Description Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine ...