最长子串(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 ...
随机推荐
- DL_1_week2_神经网络基础
二分类问题 在二分分类问题中,目标是训练出一个分类器,这里以图片特征向量x作为输入,预测输出的结果标签y是1还是0,也就是预测图片中是否有猫. 计算机保存一张图片(彩色),要保存三个 ...
- socketserver实现FTP
功能: 1.用户加密认证 2.允许同时多用户登录 3.每个用户有自己的家目录 ,且只能访问自己的家目录 4.对用户进行磁盘配额,每个用户的可用空间不同 5.允许用户在ftp server上随意切换目录 ...
- AndroidStudio制作底部导航栏以及用Fragment实现切换功能
前言 大家好,给大家带来AndroidStudio制作底部导航栏以及用Fragment实现切换功能的概述,希望你们喜欢 学习目标 AndroidStudio制作底部导航栏以及用Fragment实现切换 ...
- struts2框架学习笔记3:获取servletAPI
Struts2存在一个对象ActionContext(本质是Map),可以获得原生的request,response,ServletContext 还可以获得四大域对象(Map),以及param参数( ...
- mysql explain语法详解--优化你的查询
原文地址:http://blog.csdn.net/zhuxineli/article/details/14455029 explain显示了mysql如何使用索引来处理select语句以及连接表.可 ...
- ELK实战(Springboot日志输出查找)
需求 把分布式系统,集群日志集中处理快速查询 搭建ELK并与springboot日志输出结合 搭建ELK 基于我前面的elasticsearch搭建博客文档docker-compose.yml基础上进 ...
- Spring webFlux:坐等spring-boot-starter-data-mysql-reactive
spring-boot-starter-data-mongodb-reactive spring-boot-starter-data-redis-reactive 坐等 spring-boot-sta ...
- Info - 信息获取途径汇总
目的驱动 大多数情况下,都是为了解决某个问题或完成某项任务,才需要进行针对性的.大范围的.细致化的信息获取. 那么,信息获取的方式和来源,就应该紧紧围绕这个"问题和任务"本身来确定 ...
- Liferay7 BPM门户开发之23: 了解内置工作流(Kaleo Workflow)
Liferay内置的工作流是企业版的功能,虽然简单粗糙,但依然不支持社区版.既然要用更强大的Activiti来替代它,那就非常有必要学习一下内置工作流的一些思想,以便借鉴. 它的特点: 实体的工作流操 ...
- 自定义线程池reject策略
import java.util.Date;import java.util.concurrent.ArrayBlockingQueue;import java.util.concurrent.Rej ...