最长子串

Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

问题很简单,给你一个字符串s,问s的子串中不包含s1,s2...sn的最长串有多长。

Input

输入包含多组数据。第一行为字符串s,字符串s的长度1到10^6次方,第二行是字符串s不能包含的子串个数n,n<=1000。接下来n行字符串,长度不大于100。

字符串由小写的英文字符组成。

Output

最长子串的长度

Sample Input

lgcstraightlalongahisnstreet
5
str
long
tree
biginteger
ellipse

Sample Output

12
 
 
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std; char str[];
int len;
struct kode
{
char s[];
} a[]; struct node
{
int s,e;
} b[]; int cmp(node a,node b)
{
return a.e<b.e;
} int main()
{
int n,ans;
while(~scanf("%s",str))
{
int i,j,k;
scanf("%d",&n);
len = ;
for(i = ; i<n; i++)
{
scanf("%s",a[i].s);
int pos = ;
int l = strlen(a[i].s);
while(strstr(str+pos,a[i].s)!=NULL)
{
int f = strstr(str+pos,a[i].s)-str;
b[len].s=f;
b[len].e=f+l-;
len++;
pos = f+l-;
// printf("%d %s\n",f,str+pos);
}
}
b[len].s = b[len].e = strlen(str);
len++;
sort(b,b+len,cmp);
ans = -;
// printf("len = %d\n",len);
for(i = ; i<len; i++)
{
int tem = b[i].e-b[i-].s-;
// printf("%d\n",tem);
ans = max(ans,tem);
}
if(ans == -)
printf("%d\n",strlen(str));
else
printf("%d\n",ans); } return ;
}

最长子串(FZU2128)的更多相关文章

  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. 卷积(转自wiki百科)

    维基百科,自由的百科全书 图示两个方形脉冲波的卷积.其中函数 "g" 首先对  反射,接着平移 "t" ,成为  .那么重叠部份的面积就相当于 "t& ...

  2. Exception、Error、运行时异常与一般异常有何异同

    转自博客  https://blog.csdn.net/m0_37531231/article/details/79502778 一.开场白 对于程序运行过程中的可能出现异常情况,java语言使用一种 ...

  3. web API简介(一):API,Ajax和Fetch

    概述 今天逛MDN,无意中看到了web API简介,觉得挺有意思的,就认真读了一下. 下面是我在读的时候对感兴趣的东西的总结,供自己开发时参考,相信对其他人也有用. 什么是API API (Appli ...

  4. Swift5 语言指南(五) 基本运算符

    一个运营商是一个特殊的符号,或者你使用来检查,更改或合并值的短语.例如,加法运算符(+)添加两个数字,如,和逻辑AND运算符()组合两个布尔值,如.let i = 1 + 2&&if  ...

  5. Dispatch Queue 之 dispatch_async

     可以看到,在queue里的任务,不仅仅是一个函数,也可以是一个其他的queue. 下面是一个例子.  全局队列的处理 一般一个全局队列有多个线程,这些个线程会遍历并处理链表里的任务. 对于全局队 ...

  6. Linux - 日志文件简介

    Linux日志文件绝大多数存放在/var/log目录,其中一些日志文件由应用程序创建,其他的则通过syslog来创建. Linux系统日志文件通过syslog守护程序在syslog套接字/dev/lo ...

  7. Spring Boot Tomcat配置详解

    参数配置容器 server.xx开头的是所有servlet容器通用的配置,server.tomcat.xx开头的是tomcat特有的参数,其它类似. 所有参数绑定配置类:org.springframe ...

  8. Strom

    storm    实时分析概念        离线分析             通常是 需要一段时间的数据积累 积累到一定数量数据后 开始离线分析 无论数据量多大 离线分析 有开始 也有结束 最终得到 ...

  9. 14-01 Java matches类,Pattern类,matcher类

    Pattern类 正则表达式常见规则 A:字符 x 字符 x.举例:'a'表示字符a \\ 反斜线字符. \n 新行(换行)符 ('\u000A') \r 回车符 ('\u000D') B:字符类 [ ...

  10. [每天解决一问题系列 - 0007] 如何创建Catalog并用其签名

    问题描述: 校验一组文件的完整性 解决方法: https://msdn.microsoft.com/en-us/library/windows/desktop/aa386967(v=vs.85).as ...