#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. node路由访问,中间件返回数据

    node路由访问,中间件返回数据 定义一个变量存放json数据,中间件接受数据 var responseData; router.use(function(req, res, next) { resp ...

  2. java备份和恢复数据代码例子

    import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.F ...

  3. cpu满问题分析

    功能问题,通过日志,单步调试相对比较好定位. 性能问题,例如线上服务器CPU100%,如何找到相关服务,如何定位问题代码,更考验技术人的功底. 做为开发人员,肯定会遇到这类问题,介绍一下分析CPU 1 ...

  4. 具有增、删、改、查功能的vue-tree树组件

    最近写了一个具有增删改查功能的多级树组件,感觉很实用,啦啦啦啦, 废话不多说,看代码: tree.vue <template> <div> <div class=&quo ...

  5. Bootstrap-other内置组件

    1.缩略图 缩略图在网站中最常用的地方就是产品列表页面,一行显示几张图片,有的在图片底下(左侧或右侧)带有标题.描述等信息.Bootstrap框架将这一部独立成一个模块组件.并通过“thumbnail ...

  6. C++0X 学习之 auto

    auto并不是一个新关键词,是一个把旧关键词赋予新的作用,新的作用修饰变量声明,指示编译器根据变量的初始化表达式推导变量应有的类型.auto 声明的变量必须“在声明处完成初始化”,编译器才可根据初始化 ...

  7. Agc011_F Train Service Planning

    先放题面,再放LHX巨佬题解 接着就是%%%.$orz.Oro.Or2.Otz.OTL.sto.rzo.Jto$.On_.○| ̄|_啊 模拟赛里直接把这道题刚掉了 一题升天·爆踩全场 这题思维跨越度已 ...

  8. [转]JavaScript文件操作(2)-FileReader

    在上篇文章中,我介绍了在JavaScript操作文件,重点讲了如何取得File对象. 这些对象包含的文件的元数据在上传或者拖放到浏览器中时可以获取到.有了文件当然接下来就是读取文件了. FileRea ...

  9. spark减少提交jar包处理

    spark一个应用,算上依赖一百多兆.每一次都如此,坑. 首先是<packing>jar</packing>这只为打包为jar,在plugin中增加一个assembly插件,这 ...

  10. BZOJ2120:数颜色

    浅谈树状数组与线段树:https://www.cnblogs.com/AKMer/p/9946944.html 题目传送门:https://www.lydsy.com/JudgeOnline/prob ...