http://acm.fzu.edu.cn/problem.php?pid=2128

分析:利用strstr()函数将每个字串在原串中的首尾位置存储一下,再将首尾从小到大排一下序。(写着写着就感觉和看电视节目那一道题一样一样的啊~)

例子: aaaa  2  aa  aa  答案:1

       abc   1  d  答案:3 

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include<vector>
#include<queue>
#include<algorithm> using namespace std;
typedef long long LL; const int maxn=;
const int INF=0x3f3f3f3f;
const int mod=; char str[maxn];
char mstr[]; struct node
{
int s, e;
} a[maxn]; int cmp(node p, node q)
{
if(p.e != q.e)
return p.e<q.e; return p.s<q.s;
} int main()
{
int n, k;
while(scanf("%s", str)!=EOF)
{
scanf("%d", &n); k = ; for(int i=; i<n; i++)
{
scanf("%s", mstr); int cnt = ;
int len = strlen(mstr);
while(strstr(str+cnt, mstr)!=NULL)
{
int p = strstr(str+cnt, mstr)-str;
a[k].s = p;
a[k++].e = p + len - ;
cnt = p + len - ;
}
} a[k].s = ;
a[k++].e = strlen(str); if(k == )
{
printf("%d\n", strlen(str));
continue;
} sort(a, a+k, cmp); int maxs = -INF;
for(int i=k-; i>; i--)
maxs = max(maxs, a[i].e-a[i-].s-); printf("%d\n", maxs);
}
return ;
} /*
ab
1
c
*/

最长子串 FZU2118的更多相关文章

  1. [LeetCode] Longest Substring with At Most Two Distinct Characters 最多有两个不同字符的最长子串

    Given a string S, find the length of the longest substring T that contains at most two distinct char ...

  2. POJ 3294 Life Forms 后缀数组+二分 求至少k个字符串中包含的最长子串

    Life Forms   Description You may have wondered why most extraterrestrial life forms resemble humans, ...

  3. LeetCode: 3_Longest Substring Without Repeating Characters | 求没有重复字符的最长子串的长度 | Medium

    题目: Given a . For . 解题思路: 这个题让找一个字符串中具有不重复单词的最长子串的长度,如:ababc,子串为abc,长度为3.有这么几个方法: 方法一: 依赖字符串本身的一些特有函 ...

  4. [getLongestLength] 加和为0的最长子串长度

    点击这里查看原文 假设一个数组仅仅由1和-1组成,求该数组的和为0的最长子串的长度. 例如: {1,-1,1,-1,1,1,1} 输出:4. 昨天机试的时候做到这道题,不会做,今天思考一下. 普通的解 ...

  5. POJ-3294-Life Forms(后缀数组-不小于 k 个字符串中的最长子串)

    题意: 给定 n 个字符串,求出现在不小于 k 个字符串中的最长子串. 分析: 将 n 个字符串连起来,中间用不相同的且没有出现在字符串中的字符隔开,求后缀数组. 然后二分答案,将后缀分成若干组,判断 ...

  6. 求两个字符串最长子串的LCS算法 C语言实现(简短的实现函数)

    /************************************************************************* > File Name: lcs.c > ...

  7. Problem 2128 最长子串(kmp+strstr好题经典)

     Problem 2128 最长子串 Accept: 134    Submit: 523Time Limit: 3000 mSec    Memory Limit : 65536 KB  Probl ...

  8. fzu Problem 2128 最长子串(KMP + strstr 经典好题)

     Problem Description 问题很简单,给你一个字符串s,问s的子串中不包含s1,s2...sn的最长串有多长.  Input 输入包含多组数据.第一行为字符串s,字符串s的长度1到10 ...

  9. SPOJ PHRASES 每个字符串至少出现两次且不重叠的最长子串

    Description You are the King of Byteland. Your agents have just intercepted a batch of encrypted ene ...

随机推荐

  1. Java多线程——同步(一)

    好习惯要坚持,这是我第二篇博文,任务略重,但是要坚持努力!!! 1.竞争条件 首先,我们回顾一下<Java核心技术卷>里讲到的多线程的"竞争条件".由于各线程访问数据的 ...

  2. 【总结】我所整理的float, inline-block还有position:absolute

    这篇主要写了一下几个知识点: 浮动和inline-block的概念和选择 浮动和position:absolute对于脱离文档流的区别 这篇文章参考了一下几个链接: https://www.zhihu ...

  3. ADF_Data Binding系列2_使用URL Service Data Control

    2015-02-16 Created By BaoXinjian

  4. [Tex学习笔记]积分平均

    $\def\avint{\mathop{\mathchoice{\,\rlap{-}\!\!\int} {\rlap{\raise.15em{\scriptstyle -}}\kern-.2em\in ...

  5. ForeignKey 的第二个位置参数on_delete

    on_delete指的是通过ForeignKey连接起来的对象被删除后,当前字段怎么变化. 常见的选项有: models.CASCADE,对就对象删除后,包含ForeignKey的字段也会被删除 mo ...

  6. Linux 使用 su 切换用户提示 Authentication Failure 的解决方法

    Ubuntu v14.04,使用 su 命令切换用户时报验证失败的错误 这个问题产生的原因是由于 ubuntu 系统默认是没有激活 root 用户的,需要我们手工进行操作,在命令行界面下,或者在终端中 ...

  7. 【练习】flashback基于scn的闪回查询

    1.创建表dept1: :: SCOTT@ORA11GR2>create table dept1 as select * from dept; Table created. :: SCOTT@O ...

  8. No.016 3Sum Closest

    16. 3Sum Closest Total Accepted: 86565 Total Submissions: 291260 Difficulty: Medium Given an array S ...

  9. openldap复制

    2台主机使用镜像方式,多于2台主机使用多主方式. 部署sssd登录方式 方法见上一章节 配置复制(镜像方式) #/etc/openldap/slapd.conf配置文件,文件末尾添加以下内容 inde ...

  10. App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure.-解决办法

    运行环境:Xcode Version 7.3.1 (7D1014) 使用NSURL进行数据请求数据代码: -(NSData *)requestData{ NSURL *url = [NSURL URL ...