#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. JS正则表达式,记录自己所学所用的内容

    还没接触正则表达式感觉确实有那么点难度,但接触到后自己琢磨了几天也没发现那么难. 现在教教刚学的或者还没接触正则表达式的同学们入入门,一起学习. 正则表达式基本语法 ***************** ...

  2. BZOJ 3296 [USACO2011 Open] Learning Languages:并查集

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3296 题意: 农夫约翰的N(2 <= N <= 10,000)头奶牛,编号为1 ...

  3. 利用create-react-app从零开始搭建React移动端环境

    一 开始 1 全局安装脚手架 npm install -g create-react-app 这有个坑,就是在window下安装一直会报错,报错信息如下: 解决办法:在开始菜单栏里打开cmd的时,右击 ...

  4. php 数组分页

    $p = max(1, I('param.p',1,'intval')); $count = count($date); $Page = new Page($count,15); $Page-> ...

  5. 分享知识-快乐自己:Struts2 拦截器 与 过滤器

    拦截器的使用以及配置: package com.gdbd.interceptor; import com.gdbd.pojo.UserInfo; import com.opensymphony.xwo ...

  6. C#子线程执行完后通知主线程

    其实这个比较简单,子线程怎么通知主线程,就是让子线程做完了自己的事儿就去干主线程的转回去干主线程的事儿. 那么怎么让子线程去做主线程的事儿呢,我们只需要把主线程的方法传递给子线程就行了,那么传递方法就 ...

  7. python字符串替换之re.sub()

    re.sub(pattern, repl, string, count=0, flags=0) pattern可以是一个字符串也可以是一个正则,用于匹配要替换的字符,如果不写,字符串不做修改.\1 代 ...

  8. inux命令学习笔记(5):rm 命令

    学习了创建文件和目录的命令mkdir ,今天学习一下linux中删除文件和目录的命令: rm命令. rm是常用的命令,该命令的功能为删除一个目录中的一个或多个文件或目录,它也可以将某个目 录及其下的所 ...

  9. Cot

    题目大意 两种操作 给坐标上一个直角三角形中每个整点权值$+1$ 求坐标上一个直角三角形中每个整点权值之和 题解 一顿分析思考加推导之后,发现并不存在这样的数据结构(大概是有,只是我不知道),于是考虑 ...

  10. BZOJ1345:[Baltic2007]序列问题

    浅谈栈:https://www.cnblogs.com/AKMer/p/10278222.html 题目传送门:https://lydsy.com/JudgeOnline/problem.php?id ...