链接

[https://codeforces.com/contest/1092/problem/C]

题意

给你某个字符串的长度n,再给你2*n-2个前缀或者后缀

让你判断那些是前缀那些是后缀

关键是1到n-1的都有两个

分析

只需分析长度为n-1的那两个谁是前缀,谁是后缀

代码

#include<bits/stdc++.h>
using namespace std;
string s[210];
bool vis[110];
int main(){
int n;
//ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//freopen("in.txt","r",stdin);
while(~scanf("%d",&n)){
bool flag=0;
string s1="a",s2="b",pre;
for(int i=0;i<2*n-2;i++)
{
cin>>s[i];
if(s[i].size()==n-1&&!flag){
s1=s[i]; flag=1;
}
else if(s[i].size()==n-1) s2=s[i];
}
int cnt=0;
for(int i=0;i<2*n-2;i++)
if(s1.substr(0,s[i].size())==s[i]&&s[i]!=s2) cnt++;
//若前缀超过n-1,且s1的最长后缀等于s2的最长前缀,说明s1是前缀
if(cnt>=n-1&&s1.substr(1,s1.size()-1)==s2.substr(0,s2.size()-1))
pre=s1;
else pre=s2;//否则s2为前缀 memset(vis,0,sizeof(vis));//标记相同长度的是否已经是前缀
for(int i=0;i<2*n-2;i++)
if(s[i]==pre.substr(0,s[i].size())&&!vis[s[i].size()]) {
printf("P"); vis[s[i].size()]=1;
}
else printf("S");
puts("");
}
return 0;
}

C. Prefixes and Suffixes的更多相关文章

  1. codeforces432D Prefixes and Suffixes(kmp+dp)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud D. Prefixes and Suffixes You have a strin ...

  2. Codeforces 432D Prefixes and Suffixes(KMP+dp)

    题目连接:Codeforces 432D Prefixes and Suffixes 题目大意:给出一个字符串,求全部既是前缀串又是后缀串的字符串出现了几次. 解题思路:依据性质能够依据KMP算法求出 ...

  3. Codeforces Round #246 (Div. 2) D. Prefixes and Suffixes(后缀数组orKMP)

    D. Prefixes and Suffixes time limit per test 1 second memory limit per test 256 megabytes input stan ...

  4. Codeforces 432 D. Prefixes and Suffixes

    用扩展KMP做简单省力..... D. Prefixes and Suffixes time limit per test 1 second memory limit per test 256 meg ...

  5. Codeforces 1092C Prefixes and Suffixes(思维)

    题目链接:Prefixes and Suffixes 题意:给定未知字符串长度n,给出2n-2个字符串,其中n-1个为未知字符串的前缀(n-1个字符串长度从1到n-1),另外n-1个为未知字符串的后缀 ...

  6. CodeForces Round #527 (Div3) C. Prefixes and Suffixes

    http://codeforces.com/contest/1092/problem/C Ivan wants to play a game with you. He picked some stri ...

  7. Codeforces 432D Prefixes and Suffixes kmp

    手动转田神的大作:http://blog.csdn.net/tc_to_top/article/details/38793973 D. Prefixes and Suffixes time limit ...

  8. Codeforces Round #246 (Div. 2) D. Prefixes and Suffixes

                                                        D. Prefixes and Suffixes You have a string s = s ...

  9. CF432D Prefixes and Suffixes

    CF432D Prefixes and Suffixes 题意 给你一个长度为n的长字符串,"完美子串"既是它的前缀也是它的后缀,求"完美子串"的个数且统计这些 ...

  10. BZOJ3483 : SGU505 Prefixes and suffixes(询问在线版)

    将每个串正着插入Trie A中,倒着插入Trie B中. 并求出每个串在A,B中的dfs序. 每次查询等价于查询在A中dfs序在[la,ra]之间,在B中dfs序在[lb,rb]之间的串的个数,用主席 ...

随机推荐

  1. Spring MVC HelloWorld入门及运行机制 (一)

    完整的项目案例: springmvc.zip 介绍 SpringMVC是一款Web MVC框架. 它跟Struts框架类似,是目前主流的Web MVC框架之一. 文章通过实例来介绍SpringMVC的 ...

  2. MySQL并行复制的一个坑

    早上巡检数据库,发现一个延迟从库的sql_thread中断了. Last_SQL_Errno: 1755 Last_SQL_Error: Cannot execute the current even ...

  3. 通过一篇YAML来学习YAML

    yaml 兼容 json,至今已发展至 1.2版.支持N多种编程语言.官网:http://www.yaml.org/ 格式在线校验:http://nodeca.github.io/js-yaml/ 下 ...

  4. jQuery设置radio、select、checkbox只读属性后,如何在后台得到数据

    1 设置表单的readonly属性 对于radio.select.checkbox来说,readonly属性对这三个标签不起什么作用. 2 设置表单的disabled属性 以radio为例说明. 代码 ...

  5. Pythonic是什么?

    Python 之禅之中有这样几句话: 优美胜于丑陋(Python 以编写优美的代码为目标) 明了胜于晦涩(优美的代码应当是明了的,命名规范,风格相似) 简洁胜于复杂(优美的代码应当是简洁的,不要有复杂 ...

  6. Shell编程基础知识(一)

    一.基本的运行Linux程序的3种方法: (1) 使文件具有可执行权限,直接运行文件.eg:  chmod a+x testfile.sh   ./testfile.sh (2) 直接调用命令解释器来 ...

  7. 枚举应用demo

    package com.xx; public enum PositionEM{ ONE(1,"领导"), TWO(2,"员工"); private Long v ...

  8. 18年10月份最新免费申请微软OneDrive5TB云盘超详细教程!(已亲测!)

    本人已于今天10月23日亲测,成功获取微软OneDrive5T云盘! 第一步:.打开申请链接学生版:https://signup.microsoft.com/signup?sku=student教师版 ...

  9. VsCode放大缩小

    如图:vscode界面突然缩小了 通过快捷键 ctrl+shift+ + 放大  ctrl+shift+ - 缩小

  10. 【FJWC 2019】min

    [FJWC 2019]min 题目描述 给你一张 \(n\) 个点 \(m\) 条边的无向图,走过每条边都需要花费 \(1\) 秒. 给你一个整数 \(k\) ,请你选择至多 \(k\) 个点,令经过 ...