最长子串

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
 
 
  1. #include <stdio.h>
  2. #include <algorithm>
  3. #include <string.h>
  4. using namespace std;
  5.  
  6. char str[];
  7. int len;
  8. struct kode
  9. {
  10. char s[];
  11. } a[];
  12.  
  13. struct node
  14. {
  15. int s,e;
  16. } b[];
  17.  
  18. int cmp(node a,node b)
  19. {
  20. return a.e<b.e;
  21. }
  22.  
  23. int main()
  24. {
  25. int n,ans;
  26. while(~scanf("%s",str))
  27. {
  28. int i,j,k;
  29. scanf("%d",&n);
  30. len = ;
  31. for(i = ; i<n; i++)
  32. {
  33. scanf("%s",a[i].s);
  34. int pos = ;
  35. int l = strlen(a[i].s);
  36. while(strstr(str+pos,a[i].s)!=NULL)
  37. {
  38. int f = strstr(str+pos,a[i].s)-str;
  39. b[len].s=f;
  40. b[len].e=f+l-;
  41. len++;
  42. pos = f+l-;
  43. // printf("%d %s\n",f,str+pos);
  44. }
  45. }
  46. b[len].s = b[len].e = strlen(str);
  47. len++;
  48. sort(b,b+len,cmp);
  49. ans = -;
  50. // printf("len = %d\n",len);
  51. for(i = ; i<len; i++)
  52. {
  53. int tem = b[i].e-b[i-].s-;
  54. // printf("%d\n",tem);
  55. ans = max(ans,tem);
  56. }
  57. if(ans == -)
  58. printf("%d\n",strlen(str));
  59. else
  60. printf("%d\n",ans);
  61.  
  62. }
  63.  
  64. return ;
  65. }

最长子串(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. DL_1_week2_神经网络基础

    二分类问题 在二分分类问题中,目标是训练出一个分类器,这里以图片特征向量x作为输入,预测输出的结果标签y是1还是0,也就是预测图片中是否有猫.          计算机保存一张图片(彩色),要保存三个 ...

  2. socketserver实现FTP

    功能: 1.用户加密认证 2.允许同时多用户登录 3.每个用户有自己的家目录 ,且只能访问自己的家目录 4.对用户进行磁盘配额,每个用户的可用空间不同 5.允许用户在ftp server上随意切换目录 ...

  3. AndroidStudio制作底部导航栏以及用Fragment实现切换功能

    前言 大家好,给大家带来AndroidStudio制作底部导航栏以及用Fragment实现切换功能的概述,希望你们喜欢 学习目标 AndroidStudio制作底部导航栏以及用Fragment实现切换 ...

  4. struts2框架学习笔记3:获取servletAPI

    Struts2存在一个对象ActionContext(本质是Map),可以获得原生的request,response,ServletContext 还可以获得四大域对象(Map),以及param参数( ...

  5. mysql explain语法详解--优化你的查询

    原文地址:http://blog.csdn.net/zhuxineli/article/details/14455029 explain显示了mysql如何使用索引来处理select语句以及连接表.可 ...

  6. ELK实战(Springboot日志输出查找)

    需求 把分布式系统,集群日志集中处理快速查询 搭建ELK并与springboot日志输出结合 搭建ELK 基于我前面的elasticsearch搭建博客文档docker-compose.yml基础上进 ...

  7. Spring webFlux:坐等spring-boot-starter-data-mysql-reactive

    spring-boot-starter-data-mongodb-reactive spring-boot-starter-data-redis-reactive 坐等 spring-boot-sta ...

  8. Info - 信息获取途径汇总

    目的驱动 大多数情况下,都是为了解决某个问题或完成某项任务,才需要进行针对性的.大范围的.细致化的信息获取. 那么,信息获取的方式和来源,就应该紧紧围绕这个"问题和任务"本身来确定 ...

  9. Liferay7 BPM门户开发之23: 了解内置工作流(Kaleo Workflow)

    Liferay内置的工作流是企业版的功能,虽然简单粗糙,但依然不支持社区版.既然要用更强大的Activiti来替代它,那就非常有必要学习一下内置工作流的一些思想,以便借鉴. 它的特点: 实体的工作流操 ...

  10. 自定义线程池reject策略

    import java.util.Date;import java.util.concurrent.ArrayBlockingQueue;import java.util.concurrent.Rej ...