C. Prefixes and Suffixes
链接
[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的更多相关文章
- codeforces432D Prefixes and Suffixes(kmp+dp)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud D. Prefixes and Suffixes You have a strin ...
- Codeforces 432D Prefixes and Suffixes(KMP+dp)
题目连接:Codeforces 432D Prefixes and Suffixes 题目大意:给出一个字符串,求全部既是前缀串又是后缀串的字符串出现了几次. 解题思路:依据性质能够依据KMP算法求出 ...
- 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 ...
- Codeforces 432 D. Prefixes and Suffixes
用扩展KMP做简单省力..... D. Prefixes and Suffixes time limit per test 1 second memory limit per test 256 meg ...
- Codeforces 1092C Prefixes and Suffixes(思维)
题目链接:Prefixes and Suffixes 题意:给定未知字符串长度n,给出2n-2个字符串,其中n-1个为未知字符串的前缀(n-1个字符串长度从1到n-1),另外n-1个为未知字符串的后缀 ...
- 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 ...
- Codeforces 432D Prefixes and Suffixes kmp
手动转田神的大作:http://blog.csdn.net/tc_to_top/article/details/38793973 D. Prefixes and Suffixes time limit ...
- Codeforces Round #246 (Div. 2) D. Prefixes and Suffixes
D. Prefixes and Suffixes You have a string s = s ...
- CF432D Prefixes and Suffixes
CF432D Prefixes and Suffixes 题意 给你一个长度为n的长字符串,"完美子串"既是它的前缀也是它的后缀,求"完美子串"的个数且统计这些 ...
- BZOJ3483 : SGU505 Prefixes and suffixes(询问在线版)
将每个串正着插入Trie A中,倒着插入Trie B中. 并求出每个串在A,B中的dfs序. 每次查询等价于查询在A中dfs序在[la,ra]之间,在B中dfs序在[lb,rb]之间的串的个数,用主席 ...
随机推荐
- Java常用日期操作
对java中常用的日期操作进行整理. 1.日期格式化 /* * 日期格式化类(必须掌握) * API: * G Era 标志符 Text AD y 年 Year 1996; 96 M 年中的月份 Mo ...
- 数据库之mysql篇(1)—— 数据库管理系统简介/mysql的安装、配置
说mysql之前,还是先说说数据库. 什么是数据库: 数据库(Database)是按照数据结构来组织.存储和管理数据的仓库,它产生于距今六十多年前,随着信息技术和市场的发展,特别是二十世纪九十年代以后 ...
- Win10 C盘桌面文件右上方的两个蓝色箭头解决方案
之前看网上有很多桌面蓝色箭头的解决方案,也进行了一些尝试 可是每次Win10系统更新之后蓝色箭头就会重新显示. 最终方案:将建立在桌面的C盘文件移到D盘,桌面创建对应的快捷方式. 一劳永逸,暴力破解.
- Python - 判断list是否为空
Python中判断list是否为空有以下两种方式: 方式一: list_temp = [] if len(list_temp): # 存在值即为真 else: # list_temp是空的 方式二: ...
- centos下安装memcached
1. 通过yum安装 yum -y install memcached #安装完成后执行: memcached –h 2. Memcached 运行 //查看考号修改配置 vim /etc/s ...
- LeetCode算法题-Pascal's Triangle II(Java实现)
这是悦乐书的第171次更新,第173篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第30题(顺位题号是119).给定非负索引k,其中k≤33,返回Pascal三角形的第k ...
- Python语法基础-函数,类以及调试处理
[TOC] 1. 函数的定义 python中函数有两种: python自带的函数 用户定义函数 返回多个值 原来返回值是一个tuple!但是,在语法上,返回一个tuple可以省略括号,而多个变量可以同 ...
- Jenkins+Ansible+Gitlab自动化部署三剑客-gitlab本地搭建
实际操作 准备linux初始环境 关闭防火墙 systemctl stop firewalld 开机自己关闭 systemctl disable firewalld 设置安全配置 为关闭 vim /e ...
- Openstack window 10 镜像制作
Windows 10 Openstack 镜像制作 //************************************************************************ ...
- android studio 定位具体的错误原因
编译一个数据监测APP的时候出现了报错: Error:Compilation failed; see the compiler error output for details. 在网上查到方法如下: ...