最长子串(FZU2128)
最长子串
Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Description
Input
输入包含多组数据。第一行为字符串s,字符串s的长度1到10^6次方,第二行是字符串s不能包含的子串个数n,n<=1000。接下来n行字符串,长度不大于100。
字符串由小写的英文字符组成。
Output
Sample Input
Sample Output
#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)的更多相关文章
- [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 ...
- POJ 3294 Life Forms 后缀数组+二分 求至少k个字符串中包含的最长子串
Life Forms Description You may have wondered why most extraterrestrial life forms resemble humans, ...
- LeetCode: 3_Longest Substring Without Repeating Characters | 求没有重复字符的最长子串的长度 | Medium
题目: Given a . For . 解题思路: 这个题让找一个字符串中具有不重复单词的最长子串的长度,如:ababc,子串为abc,长度为3.有这么几个方法: 方法一: 依赖字符串本身的一些特有函 ...
- [getLongestLength] 加和为0的最长子串长度
点击这里查看原文 假设一个数组仅仅由1和-1组成,求该数组的和为0的最长子串的长度. 例如: {1,-1,1,-1,1,1,1} 输出:4. 昨天机试的时候做到这道题,不会做,今天思考一下. 普通的解 ...
- POJ-3294-Life Forms(后缀数组-不小于 k 个字符串中的最长子串)
题意: 给定 n 个字符串,求出现在不小于 k 个字符串中的最长子串. 分析: 将 n 个字符串连起来,中间用不相同的且没有出现在字符串中的字符隔开,求后缀数组. 然后二分答案,将后缀分成若干组,判断 ...
- 求两个字符串最长子串的LCS算法 C语言实现(简短的实现函数)
/************************************************************************* > File Name: lcs.c > ...
- Problem 2128 最长子串(kmp+strstr好题经典)
Problem 2128 最长子串 Accept: 134 Submit: 523Time Limit: 3000 mSec Memory Limit : 65536 KB Probl ...
- fzu Problem 2128 最长子串(KMP + strstr 经典好题)
Problem Description 问题很简单,给你一个字符串s,问s的子串中不包含s1,s2...sn的最长串有多长. Input 输入包含多组数据.第一行为字符串s,字符串s的长度1到10 ...
- SPOJ PHRASES 每个字符串至少出现两次且不重叠的最长子串
Description You are the King of Byteland. Your agents have just intercepted a batch of encrypted ene ...
随机推荐
- MVC 5使用TempData Object跨视图传递数据
经过一系列显示数据的练习:<MVC 5使用ViewData(对象)显示数据>http://www.cnblogs.com/insus/p/3377178.html<MVC 5使用Vi ...
- Python脱产8期 Day014 2019/4/28
一 带参装饰器 1.通常,装饰器为被装饰的函数添加新功能,需要外界的参数 # -- outer参数固定一个,就是func # -- inner参数固定同被装饰的函数,也不能添加新参数 # -- 可以借 ...
- 2019-4-22 linux学习
linux 一.linux的目录结构 / 挂载目录:为所有目录的根目录 home 家目录: 用户的根目录 存放普通用户的文件 例如:创建一个jack用户,就会产生一个Jack ...
- [CocoaPods]客户端加载第三方库
请先阅读另一篇博文铺垫知识基础:[CocoaPods]终端方式集成第三方库 客户端的Github地址:CocoaPods-app 点击下载客户端: [CocoaPods客户端] 安装下载的文件.软件界 ...
- celery异步认知
celery是异步任务的框架 是由python实现的异步框架. 在使用celery我们经常分为三个部分, 第一部分就是我们所说的客户端, 就是发起异步任务的一方, 第二部分 任务队列 broker 第 ...
- 物体检测,Error: maximum box coordinate value is too large
使用ssd目标检测,出现error:maximum box coordinate value is larger than 1.100000: ] [1.325] 主要原因在于,用labelImg 标 ...
- RabbitMQ常见错误1
java.lang.IllegalStateException: Invalid configuration: 'exchange' must be non-null. at com.rabbitmq ...
- web自动化测试---测试环境的部署
当前我的测试环境配置如下: python3.6 下载地址: https://www.python.org/downloads/release/python-365/ 选择windows版本,下载完成后 ...
- 关于springboot aop 俩次调用的问题 aop多次调用
由于我在springboot 启动类中 给我的切面类进行了赋值 即@Bean 然而我在切面类中加了@Component 导致 springboot 注入了俩个 bean 所以导致 aop 多次执行 ...
- Linux基础命令 ls
目录 1. ls 列出目录的内容 -a --all: -A --almost-all: -b --escape: --block-size=SIZE: --color: --d --directory ...