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. c语言单向链表逆转实现方法

    自己理解的思路如下所示: 从第二个节点开始,先记录下一个节点,把第二个节点移到头节点之前,头节点变为移动的这个节点之前记录的节点变为接下来要移动的节点用for循环重复最后把原来头节点变成尾节点(*ne ...

  2. Anaconda快速加载opencv

    刚刚发现了两种Anaconda快速加载opencv的方法,亲测有效: 第一种: 直接在Navigator Environment 中搜opencv 如果搜不到,登陆Anaconda Cloud官网 h ...

  3. java入门---运算符&逻辑运算符&短路逻辑运算符&赋值运算符&条件运算符&instanceof 运算符

        这篇文章接着上次的来,主要看逻辑运算符&短路逻辑运算符&赋值运算符&条件运算符&instanceof 运算符这五种运算符.     首先来看逻辑运算符.下表列出 ...

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

    20155206 2006-2007-2 <Java程序设计>第4周学习总结 教材学习内容总结 继承: 避免多个类间重复定义共同行为,在编写程序的过程中可能会出现部分代码重复的现象,把重复 ...

  5. IDEA下安装与使用Junit4

    安装Junit4 打开File->Settings->Plugins,单击下图所示按钮 搜索JunitGeneratorV2.0并安装 重启IDEA 打开File->Project ...

  6. 【私人向】Java复习笔记

    此笔记学习于慕课网:Java入门第一季-第三季,想学的可以点击链接进行学习,笔记仅为私人收藏 建议学习时间:2-3天(极速版) 数据类型 基本数据类型存的是数据本身 引用类型变量(class.inte ...

  7. 20155317 王新玮 2016-2017-2 《Java程序设计》第5周学习总结

    20155317 王新玮 2016-2017-2 <Java程序设计>第5周学习总结 教材学习内容总结 异常处理 & Collection与Map 异常继承架构 错误的对象继承ja ...

  8. eclipse 打包maven项目的坑

    一.问题: 公司开发了一个项目,需要作为后台服务运行,整个项目的构成是:[maven + spring + eclipse] 在使用打包的时候遇到许多问题: (1)eclipse中maven工具的集成 ...

  9. 【转载】DXUT进阶

    原文:DXUT进阶 概要 这个指南涵盖了更多DXUT的高级应用. 这个指南里的大部分功能是可选的, 为了以最小的代价来增强你的应用程序. DXUT提供了一个简单的基于GUI系统的精灵和一个设备设置对话 ...

  10. Windows下安装RaibbitMQ

    1.软件准备 1.1 erlang语言包 到http://www.erlang.org/download.html下载,并且运行! 安装目录C:\Program Files (x86)\erl5.10 ...