#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+7;
pair<string,int>p[maxn];
int nn,n;
int cmp(pair<string,int>a,pair<string,int>b){
    return a.first.length()<b.first.length();
}
char ans[maxn];
multiset<string>sst;
int judge(string pre,string suf){
    string s=pre+suf[suf.length()-1];//将最长的加上同样长的另一个字符可以拼接成完整串(或是完整串的镜像)
    multiset<string>st;
    for(int i=0;i<n-1;i++){
        st.insert(s.substr(0,i+1));//0-i+1
        st.insert(s.substr(i+1));//i+1-end
    }//将所有前缀后缀全被扔进多重集st中
    if(st!=sst)//镜像
        return 0;
    for(int i=1;i<=nn;i+=2){
        string ss=s.substr(0,p[i].first.length());//截取长度开始比较,string的优势在于可以直接等于比较
        string sss=s.substr(n-p[i].first.length());
        if(p[i].first==ss && p[i+1].first==sss){
            ans[p[i].second]='P';
            ans[p[i+1].second]='S';
        }
        else{
            ans[p[i+1].second]='P';
            ans[p[i].second]='S';
        }
    }
    return 1;
}
int main(){
    scanf("%d",&n);
    nn=2*n-2;
    for(int i=1;i<=nn;i++){
        cin>>p[i].first;
        p[i].second=i;
        sst.insert(p[i].first);
    }
    sort(p+1,p+1+nn,cmp);
    if(judge(p[nn].first,p[nn-1].first)){
        for(int i=1;i<=nn;i++){
            printf("%c",ans[i]);
        }
    }
    else if(judge(p[nn-1].first,p[nn].first)){
        for(int i=1;i<=nn;i++){
            printf("%c",ans[i]);
        }
    }
    return 0;
}
 

Codeforces Round #527 (Div. 3)C(多重集,STRING)的更多相关文章

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

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

  2. 贪心 Codeforces Round #303 (Div. 2) B. Equidistant String

    题目传送门 /* 题意:找到一个字符串p,使得它和s,t的不同的总个数相同 贪心:假设p与s相同,奇偶变换赋值,当是偶数,则有答案 */ #include <cstdio> #includ ...

  3. Codeforces Round #354 (Div. 2)_Vasya and String(尺取法)

    题目连接:http://codeforces.com/contest/676/problem/C 题意:一串字符串,最多改变k次,求最大的相同子串 题解:很明显直接尺取法 #include<cs ...

  4. Codeforces Round #303 (Div. 2) B. Equidistant String 水题

    B. Equidistant String Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/54 ...

  5. 【Codeforces Round #423 (Div. 2) C】String Reconstruction

    [Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...

  6. Codeforces Round #604 (Div. 2) A. Beautiful String

    链接: https://codeforces.com/contest/1265/problem/A 题意: A string is called beautiful if no two consecu ...

  7. Codeforces Round #656 (Div. 3) D. a-Good String

    题目链接:https://codeforces.com/contest/1385/problem/D 题意 一个小写字母串称为 $c-good\ string$,如果至少满足以下条件之一: 字符串长度 ...

  8. Codeforces Round #604 (Div. 2) A. Beautiful String(贪心)

    题目链接:https://codeforces.com/contest/1265/problem/A 题意 给出一个由 a, b, c, ? 组成的字符串,将 ? 替换为 a, b, c 中的一个字母 ...

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

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

随机推荐

  1. 分享知识-快乐自己:Liunx 根目录结构

  2. 三 Django框架,Views(视图函数),也就是逻辑处理函数里的各种方法与属性

    Django框架,Views(视图函数),也就是逻辑处理函数里的各种方法与属性 Views(视图函数)逻辑处理,最终是围绕着两个对象实现的 http请求中产生两个核心对象: http请求:HttpRe ...

  3. GUI创建各常用控件(一)

    首先,作个申明: 1.这是一个野路子非科班的小菜鸟的学习,故诚心欢迎批评指正(同时所述内容可能有误): 2.本人目前使用的Unity3D版本为 5.3.5: 言归正传! 事实上在开发过程中已经很少用G ...

  4. jmeter 多压力机并发测试过程

    要实现多台压力机并发,就必须有多台服务器上安装了jmeter程序包,首先把一台服务器作为主压力机,测试脚本放到这台机器上,主压力机与从压力机在同一局域网中,服务器之间可以ping通 第一步:在linu ...

  5. Android repo 学习参考

    /*************************************************************************** * Android repo 学习参考 * 说 ...

  6. [原]NYOJ-小光棍数-458

    大学生程序代写 /http://acm.nyist.net/JudgeOnline/problem.php?pid=458 *题目458题目信息运行结果本题排行讨论区小光棍数 时间限制:1000 ms ...

  7. 洛谷【P1885】Moo

    我对分治的理解:https://www.cnblogs.com/AKMer/p/9728574.html 题目传送门:https://www.luogu.org/problemnew/show/P18 ...

  8. 最长递增子序列(LIS)

    最长递增子序列(Longest Increasing Subsequence) ,我们简记为 LIS. 题:求一个一维数组arr[i]中的最长递增子序列的长度,如在序列1,-1,2,-3,4,-5,6 ...

  9. ThinkPHP5.1的公共函数

    最初使用ThinkPHP3.2.3的时候,我们自己定义的公共函数常常放置于 \Common\function.php ThinkPHP5.1 公共函数 项目公用的会放在 \application\co ...

  10. Mybatis连接mysql数据库出现乱码

    对于mysql数据库的乱码问题,有两中情况: 1. mysql数据库编码问题(建库时设定). 2. 连接mysql数据库的url编码设置问题. 对于第一个问题,目前个人发现只能通过重新建库解决,建库的 ...