第一组实例

aaaa

2

aa

aa



第二组

a

1

c



第三组

abcdef

2

abcd

bcd





第四组



abcdef

2

abcd

bcde

第五组

aaaa

2

a

aa



第六组

lgcstraightlalongahisnstreet

5

str

long

tree

biginteger

ellipse

#include<stdio.h>

#include<string.h>//考虑了很多实例

#include<stdlib.h>

#define N  1100000

char  s[N],str[1100][200];

struct node {

int start,end,index;

}hst[N],hen[N];

int cmp(const void *a,const void *b) {

return (*(struct node *)a).start>(*(struct node *)b).start?1:-1;

}

int compare(const void *a,const void *b) {

return (*(struct node *)a).end>(*(struct node *)b).end?1:-1;

}

int main() {

int n,max,index,to,ans,start,end,i,j;

while(scanf("%s",s)!=EOF) {

scanf("%d",&n);

index=0;

for(i=0;i<n;i++) {

scanf("%s",str[i]);

to=0;

for(j=0;j<i;j++)

if(strcmp(str[j],str[i])==0)//第一组

to=1;

if(to)

continue;

while(1) {

if(strstr(s+to,str[i])==NULL)

break;

hst[index].index=index;

hst[index].start=strstr(s+to,str[i])-&s[0];

hst[index].end=hst[index].start+strlen(str[i])-1;

hen[index]=hst[index];

to=hst[index].start+1;

index++;

}

}

if(index==0) {//第二组

printf("%d\n",strlen(s));

continue;

}

qsort(hst,index,sizeof(hst[0]),cmp);

qsort(hen,index,sizeof(hen[0]),compare);

   start=hen[0].end;

   end=strlen(s)-hst[index-1].start-1;

   max=end>start?end:start;

for(i=0;i<index;i++) {

           ans=0;

           for(j=0;j<index;j++)

  if(hen[j].index!=hst[i].index&&hen[j].end>=hst[i].start)  {

                  ans=hen[j].end-hst[i].start-1;

 break;

  }

  if(max<ans)

  max=ans;

}

printf("%d\n",max);

}

return 0;

}

fzu 2128的更多相关文章

  1. fzu 2128 AC自动机

    链接   http://acm.fzu.edu.cn/problem.php?pid=2128 解题方法  首先考虑暴力,,就是拿每一个字符串在匹配串里面找到所有位置,然后从头到尾不断更新最长的合理位 ...

  2. 福州大学第十届校赛 & fzu 2128最长子串

    思路: 对于每个子串,求出 母串中 所有该子串 的 开始和结束位置,保存在 mark数组中,求完所有子串后,对mark数组按 结束位置排序,然后 用后一个的结束位置 减去 前一个的 开始 位置 再 减 ...

  3. FZU 2128 最长子串

    题目链接:最长子串 思路:依次找出每个子串的在字符串中的首尾地址,所有子串先按照尾地址从小到大排序.然后首地址从小到大排. 遍历一遍每个子串的首地址和它后面相邻子串的尾地址之差-1, 第一个子串的首地 ...

  4. 最长子串(FZU2128)

    最长子串 Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status  ...

  5. fzu Problem 2128 最长子串(KMP + strstr 经典好题)

     Problem Description 问题很简单,给你一个字符串s,问s的子串中不包含s1,s2...sn的最长串有多长.  Input 输入包含多组数据.第一行为字符串s,字符串s的长度1到10 ...

  6. FZU 2137 奇异字符串 后缀树组+RMQ

    题目连接:http://acm.fzu.edu.cn/problem.php?pid=2137 题解: 枚举x位置,向左右延伸计算答案 如何计算答案:对字符串建立SA,那么对于想双延伸的长度L,假如有 ...

  7. FZU 1914 单调队列

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=1914 题意: 给出一个数列,如果它的前i(1<=i<=n)项和都是正的,那么这个数列是正的,问这个 ...

  8. ACM: FZU 2105 Digits Count - 位运算的线段树【黑科技福利】

     FZU 2105  Digits Count Time Limit:10000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  9. FZU 2112 并查集、欧拉通路

    原题:http://acm.fzu.edu.cn/problem.php?pid=2112 首先是,票上没有提到的点是不需要去的. 然后我们先考虑这个图有几个连通分量,我们可以用一个并查集来维护,假设 ...

随机推荐

  1. spring web中的filter

    昨天看了会spring web中部分代码,主要是各种filter,回顾一下: Spring的web包中中有很多过滤器,这些过滤器位于org.springframework.web.filter并且理所 ...

  2. bzoj1407

    扩展欧几里得 我们发现其实就是两个野人在自己的寿命内不会相遇,或者永远不会相遇,那么我们枚举m,然后枚举两个人,看是否符合条件 扩展欧几里得ax+by=c,这里c不能取模,a能取模,具体不想了 #in ...

  3. 使用 typescript 开发 Vue

    基础配置: 1. 准备一个使用 vue-cli 生成的项目 2. 使用 npm 一建安装基础配置 npm i -S @types/node typescript vue-class-component ...

  4. 51nod1565 FFT

    思路: 显然拆位FFT 不解释 //By SiriusRen #include <bits/stdc++.h> using namespace std; ; ); ,L,S,T,k,sa[ ...

  5. 题解报告:hdu 1028 Ignatius and the Princess III(母函数or计数DP)

    Problem Description "Well, it seems the first problem is too easy. I will let you know how fool ...

  6. [转]linux之diff 命令

    转自:http://www.cnblogs.com/peida/archive/2012/12/12/2814048.html diff 命令是 linux上非常重要的工具,用于比较文件的内容,特别是 ...

  7. Html基础学习(基于W3school网络教程)

    //防止乱码 head中加入 <meta http-equiv="Content-Type" content="text/html; charset=utf-8&q ...

  8. Android icon尺寸

    Android icon尺寸   密度范围 切图比例(以mdpi为基准) 切图比例(以xxxhdpi为基准) 图标尺寸 外间距 ((图标尺寸-图片尺寸)/2) mdpi 120dpi~160dpi 1 ...

  9. html5——web存储

    基本概念 1.传统方式我们以document.cookie来进行存储的,但是由于其存储大小只有4k左右,并且解析也相当的复杂,给开发带来诸多不便 2.h5存储设置.读取方便,而且容量较大,sessio ...

  10. Android ExpandableListView的使用详解

    ExpandableListView(可扩展的ListView) ExpandableListVivew是ListView的子类,它在普通ListView的基础上进行了扩展,它把应用中的列表项分为几组 ...