#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. mysql 如何创建索引

    mysql 如何创建索引 一.总结 一句话总结:MySQL中可以使用alter table这个SQL语句来为表中的字段添加索引. 使用alter table语句来为表中的字段添加索引的基本语法是:AL ...

  2. Myeclipse或者Eclipse恢复默认启动时显示选择workspace的问题

    [问题描述] 不知道是不是Myeclipse8.5的Bug,我最近安装了8.5之后,前面几天打开MyEclipse的时候都是让我自己选择工作空间的,但是最近突然每次打开的时候都自己打开了C盘下面工作空 ...

  3. JS获取ListBox所有项

    JS代码: var listbox = document.getElementById("<%=lbCustom.ClientID %>"); var values = ...

  4. Hibernate学习---第十三节:hibernate过滤器和拦截器的实现

    一.hibernate 过滤器 1.在持久化映射文件中配置过滤器,代码如下: <?xml version="1.0"?> <!DOCTYPE hibernate- ...

  5. L104

    marsh:It was like my own marsh country, flat and monotonous.The government will take more measures t ...

  6. codeforces 632C C. The Smallest String Concatenation(sort)

    C. The Smallest String Concatenation time limit per test 3 seconds memory limit per test 256 megabyt ...

  7. ACM学习历程—广东工业大学2016校赛决赛-网络赛C wintermelon的魔界寻路之旅(最短路 && 递推)

    题目链接:http://gdutcode.sinaapp.com/problem.php?cid=1031&pid=2 题目由于要找对称的路径,那么狠明显可以把右下角的每一块加到左上角对应的每 ...

  8. PLSQL Developer安装、配置、连接oracle数据库

    0.资源准备 1) PLSQL Developer安装包(由于安装包超过10M,无法上传,请自行下载) 2) instantclient_11_2安装包(由于安装包超过10M,无法上传,请自行下载) ...

  9. Maven: 自动远程部署

    1. 在settings.xml中的Servers节点中增加Server的登录信息: <server> <id>deploy_server_65</id> < ...

  10. bzoj 3083 遥远的国度 —— 树链剖分

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3083 换根后路径还是不变,子树分类讨论一下,树剖后线段树维护即可. 代码如下: #inclu ...