最长子串(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 ...
随机推荐
- 基于ESP32的uart通讯
本文源码地址为:http://download.csdn.net/download/noticeable/9961054 ESP32上有三个UART通讯接口,设备号,从0~2,即UART0,UART1 ...
- Spring Boot Actuator 使用
转载于:https://www.jianshu.com/p/af9738634a21 Spring Boot 的 Actuator 提供了很多生产级的特性,比如监控和度量Spring Boot 应用程 ...
- unigui日志
unigui日志 uniGUI本身提供了日志功能,利用uniServerModule.ServerLogger来控制如何写日志: Enabled:是否写日志 Options:logIndyExcept ...
- leetcode144-先序遍历非递归实现
二叉树的先序/中序/后序遍历递归/非递归实现,讲的很清楚,其中后序遍历和先序中序的处理有些不一样: https://blog.yangx.site/2016/07/22/Python-binary-t ...
- 项目Alpha冲刺(团队3/10)
项目Alpha冲刺(团队3/10) 团队名称: 云打印 作业要求: 项目Alpha冲刺(团队) 作业目标: 完成项目Alpha版本 团队队员 队员学号 队员姓名 个人博客地址 备注 221600412 ...
- 关于elasticsearch function_score的使用
最近做新闻推荐系统,新闻搜索采用的是elasticsearch引擎,为了使推荐更接近用户偏好,搜索时使用了function_score功能对文档进行了重新打分,改变排序规则.以下介绍关于functio ...
- kubernetes集群搭建(6):kubernetes基本使用演示
以简单部署访问来演示kubernetes的基本使用 流程: 用户访问client应用,client应用中调用server应用,由于部署了多节点,client在访问server时应该配置server 暴 ...
- python学习记录(一)
1.打印操作 >>> print('hello') hello >>> print(1+2) 3 2.字符串操作 ① ') Traceback (most rece ...
- 当强制关机时,出现Eclipse打不开的问题
关于Eclipse或MyEclipse启动卡死的问题(即Eclipse上一次没有正确关闭,导致启动的时候卡死错误解决方法): 方案1:(推荐使用,如果没有这个文件,就使用方案2,方案2基本上 ...
- 课程四(Convolutional Neural Networks),第一周(Foundations of Convolutional Neural Networks) —— 2.Programming assignments:Convolutional Model: step by step
Convolutional Neural Networks: Step by Step Welcome to Course 4's first assignment! In this assignme ...