题目链接:Prefixes and Suffixes

题意:给定未知字符串长度n,给出2n-2个字符串,其中n-1个为未知字符串的前缀(n-1个字符串长度从1到n-1),另外n-1个为未知字符串的后缀(n-1个字符串长度从1到n-1),判断这2n-2个字符串分别为前缀还是后缀。

题解:从2n-2从找个n-1长度的字符串和1长度的字符串拼接,判断该字符串是否符合要求,能作为未知字符串。符合的话,直接输出答案。

 #include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <fstream>
#include <iostream>
#include <algorithm>
using namespace std; #define eps 1e-8
#define pb push_back
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define clr(a,b) memset(a,b,sizeof(a)
#define FAST_IO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) typedef long long ll;
typedef unsigned long long ull;
int n,m;
string str[];
map <string,int> M; void solve(string s){
for(int i=;i<=m;i++){
bool ok=;
int sz=str[i].size();
if(s.substr(,sz)==str[i]) ok=;
if(s.substr(n-sz)==str[i]) ok=;
if(!ok) return ;
}
for(int i=;i<=m;i++){
int sz=str[i].size();
if(s.substr(,sz)==str[i]&&s.substr(n-sz)==str[i]){
if(M[str[i]]) cout<<"S",M[str[i]]=;
else cout<<"P",M[str[i]]=;
}
else if(s.substr(n-sz)==str[i]) cout<<"S";
else if(s.substr(,sz)==str[i]) cout<<"P";
}
cout<<endl;
exit();
} int main(){
FAST_IO;
cin>>n;
m=*n-;
for(int i=;i<=m;i++) cin>>str[i];
for(int i=;i<=m;i++){
for(int j=;j<=m;j++){
if(str[i].size()==n-&&str[j].size()==)
solve(str[i]+str[j]);
}
}
return ;
}

Codeforces 1092C Prefixes and Suffixes(思维)的更多相关文章

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

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

  2. Codeforces 432D Prefixes and Suffixes kmp

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

  3. Codeforces Round #527 (Div. 3) C. Prefixes and Suffixes (思维,字符串)

    题意:给你某个字符串的\(n-1\)个前缀和\(n-1\)个后缀,保证每个所给的前缀后缀长度从\([1,n-1]\)都有,问你所给的子串是前缀还是后缀. 题解:这题最关键的是那两个长度为\(n-1\) ...

  4. codeforces - 432D Prefixes and Suffixes (next数组)

    http://codeforces.com/problemset/problem/432/D 转自:https://blog.csdn.net/tc_to_top/article/details/38 ...

  5. Codeforces 432D Prefixes and Suffixes:KMP + dp

    题目链接:http://codeforces.com/problemset/problem/432/D 题意: 给你一个字符串s,让你找出所有既是前缀又是后缀的子串,并输出它们分别出现了多少次. 题解 ...

  6. Codeforces 432D Prefixes and Suffixes (KMP、后缀数组)

    题目链接: https://codeforces.com/contest/432/problem/D 题解: 做法一: KMP 显然next树上\(n\)的所有祖先都是答案,出现次数为next树子树大 ...

  7. codeforces 432D Prefixes and Suffixes

    由于包含了前缀与后缀,很容易想到用KMP去算前缀与后缀的公共缀.另外要计算某个后缀在整个串中出现的次数,由于后缀自动机是比较容易求的,然后就直接上后缀自动机了.先分别用KMP算法与后缀自动机跑一遍,然 ...

  8. 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 ...

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

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

随机推荐

  1. Kafka学习资料

    博客系列: Apache Kafka简介Apache Kafka安装和使用Apache Kafka核心概念kafka核心组件和流程—控制器kafka核心组件和流程—协调器kafka核心组件和流程—日志 ...

  2. 一个简易的Python爬虫,将爬取到的数据写入txt文档中

    代码如下: import requests import re import os #url url = "http://wiki.akbfun48.com/index.php?title= ...

  3. 模板引擎artTemplate的使用

    1.引入template文件 <script src = js/template-native.js></script> 2.写模板 <script type=" ...

  4. Django 使用 locals() 函数

    locals() 函数会以字典类型返回当前位置的全部局部变量. 在 views.py 中添加 from django.shortcuts import render,HttpResponse,rend ...

  5. 五分钟读懂UML类图(转)

    平时阅读一些远吗分析类文章或是设计应用架构时没少与UML类图打交道.实际上,UML类图中最常用到的元素五分钟就能掌握,下面赶紧来一起认识一下它吧: 一.类的属性的表示方式 在UML类图中,类使用包含类 ...

  6. Golang学习笔记(一)

    这个系列学习文章是对ASTAXIE大神的GoWeb编程的读书笔记. 1. 关于GOPATH $GOPATH 是系统中重要的环境变量,他不是Go的安装目录. 假如我们将GOPATH设置在这里: /hom ...

  7. (爬虫)urllib库

    一.爬虫简介 什么是爬虫?通俗来讲爬虫就是爬取网页数据的程序. 要了解爬虫,还需要了解HTTP协议和HTTPS协议:HTTP协议是超文本传输协议,是一种发布和接收HTML页面的传输协议:HTTPS协议 ...

  8. cvc-elt.1: Cannot find the declaration of element 'beans'Failed to read schema document 'http://www.springframework.org/schema/beans/spring- beans-3.0.xsd'

    Multiple annotations found at this line: - cvc-elt.1: Cannot find the declaration of element 'beans' ...

  9. 【记录】垃圾清理软件 便携版CleanMyPC破解版

    摘要 使用CleanMyPC保持您的PC清洁并像新的一样运行.它扫描整个计算机以清理垃圾文件,加速您的PC并提高其性能.CleanMyPC不仅仅是一台PC清洁工 - 它是关注计算机的必备工具.[有能力 ...

  10. 解释型语言VS编译型语言

    前言 计算机不能直接理解除机器语言以外的语言,所以只有把程序员编写的程序翻译成机器语言,计算机才能够执行程序. 将其他语言翻译成机器语言的工具,被称之为:编译器. 编译器的翻译方式有两种:编译和解释. ...