最长子串(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 ...
随机推荐
- Alpha冲刺 - (8/10)
Part.1 开篇 队名:彳艮彳亍团队 组长博客:戳我进入 作业博客:班级博客本次作业的链接 Part.2 成员汇报 组员1(组长)柯奇豪 过去两天完成了哪些任务 进一步优化代码,结合自己负责的部分修 ...
- iOS逆向之class-dump
1.class-dump class-dump是用来dump目标文件的类信息的工具.它利用Objective-C语言的runtime的特性,将存储在mach-O文件中的@interface和@prot ...
- 9.7 翻译系列:EF数据注解特性之--InverseProperty【EF 6 Code-First系列】
原文链接:https://www.entityframeworktutorial.net/code-first/inverseproperty-dataannotations-attribute-in ...
- ASP.NET MVC下使用AngularJs语言(六):获取下拉列表的value和Text
前面Insus.NET有在Angularjs实现DropDownList的下拉列表的功能.但是没有实现怎样获取下拉列表的value和text功能. 下面分别使用ng-click和ng-change来实 ...
- Servlet案例1:用户登录
数据库准备: CREATE DATABASE web; USE web; CREATE TABLE users( id INT PRIMARY KEY AUTO_INCREMENT, username ...
- Spring controller 中接收JSON参数失败
如果方法中的参数都是JSON类型,则在方法参数前面添加 @RequestBody 注解: public Boolean serverPath(@RequestBody ServerPathReq r ...
- MySQL 组提交(group commit)
目录 前言 改进 原理 实现 参数 注意 前言 操作系统使用页面缓存来填补内存和磁盘访问的差距 对磁盘文件的写入会先写入道页面缓存中 由操作系统来决定何时将修改过的脏页刷新到磁盘 确保修改已经持久化到 ...
- Maven - 实例-2-使用本地仓库中的依赖包
Maven引入构建包的流程 执行mvn compile命令编译源代码,如果编译过程中需要用到其他的包, maven将会在pom.xml文件中查找是否引入该依赖包的坐标. 示例: <depende ...
- Xamarin.Android 使用 SQLite 出现 Index -1 requested, with a size of 10 异常
异常: Android.Database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 10 此错误是数据返回 ...
- FF笔试题整理
一.选择题 1.怎样能唯一确定一颗二叉树? [解析] 只要知道中序遍历顺序,再加上其余两个遍历中任意一个都可以唯一确定一个二叉树.如果不知道中序遍历顺序,则无法确定. [反例] A-B-C,A是跟,B ...