fzu Problem 2128 最长子串

来源:互联网 发布:java命令行运行jar包 编辑:程序博客网 时间:2024/06/11 02:10

http://acm.fzu.edu.cn/problem.php?pid=2128

 

#include"stdio.h"
#include"string.h"
#include"stdlib.h"
struct point
{
 int x;
 int y;
}sum[1000006];
int cmp(const void *a,const void *b)
{
 struct point *c=(point *)a;
 struct point *d=(point *)b;
 return c->x-d->x;
}
char s[1000006],a[1006][106];
int main()
{
 int i,j,k,h;
 
 while(scanf("%s",s)!=EOF)
 {
  j=0;
  int max=-1,pp;
  scanf("%d",&k);
  for(i=0;i<k;i++)
  {
   h=0;
   scanf("%s",a[i]);
   while(strstr(s+h,a[i])!=NULL)
   {
    sum[j].x=strstr(s+h,a[i])-s;
    h=strstr(s+h,a[i])-s+strlen(a[i])-1;
    sum[j].y=h;
    j++;
   }
  }
  sum[j].x=sum[j].y=strlen(s);
  j++;
  qsort(sum,j,sizeof(sum[0]),cmp);
  
  for(i=0;i<j-1;i++)
  {
  pp=sum[i+1].y-sum[i].x-1;
  if(pp>max)
   max=pp; 
  }
  if(max!=-1)
  printf("%d\n",max);
  else
   printf("%d\n",strlen(s));
 
 }
 return 0;
}

 

0 0
原创粉丝点击