第一组实例

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. [luogu_U15118]萨塔尼亚的期末考试

    https://zybuluo.com/ysner/note/1239615 题面 \(T\)次询问,求出\[\sum_{i=1}^n\frac{i}{\frac{n(n+1)}{2}}fib_i\] ...

  2. Makefile 实际用例分析(一) ------- 比较通用的一种架构

    这里不再说Makefile的基本知识,如果需要学习,那么请参考: 下载:makefile 中文手册 或者 点击打开链接 或者 跟我一起写Makefile( 陈皓 ) 这里说的是一般的实际的一个工程应该 ...

  3. IDEA Spark Streaming Flume数据源 --解决无法转化为实际输入数据,及中文乱码(Scala)

    需要三步: 1.shell:往 1234 端口写数据 nc localhost 1234 2.shell: 启动flume服务 cd /usr/local2/flume/bin ./flume-ng ...

  4. php的类型转换

    转自:http://www.tianzhigang.com/article.asp?id=280 PHP的数据类型转换属于强制转换,允许转换的PHP数据类型有: (int).(integer):转换成 ...

  5. 洛谷P1478 陶陶摘苹果(升级版)

    题目数据范围小,开两个数组手写冒泡应该也能过,不过和之前在牛客上的一题类似用结构体数组就好了,主要是注意用结构体数组的排序 题目 题目描述 又是一年秋季时,陶陶家的苹果树结了n个果子.陶陶又跑去摘苹果 ...

  6. 题解报告:hdu 1162 Eddy's picture

    Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to become ...

  7. java环境搭建(及安装问题“No repository found containing”解决) 并创立第一个java程序

    环境: java8 及 Eclipse java8 配置:http://jingyan.baidu.com/article/e2284b2b5967e7e2e7118d74.html Eclipse ...

  8. linux对比两个文件的差异

    在项目维护阶段,经常会对垃圾文件进行清理.比如没有在数据库中的文件进行删除,这个时候最好的选择就是使用shell命令了:废话不多说直接上代码: 1.首先准备好从数据表导出来的数据,方法随意 2.在服务 ...

  9. Python3之format

    print('{0},{1}'.format('zhangk', 32)) print('{},{},{}'.format('zhangk','boy',32)) print('{name},{sex ...

  10. C# ADO.NET动态数据的增删改查(第五天)

    一.插入登录框中用户输入的动态数据 /// <summary> /// 添加数据 /// </summary> /// <param name="sender& ...