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;
}