标签:
题目链接:http://acm.fzu.edu.cn/problem.php?pid=2128
刚开始怎么也看不出来样例的答案;还好突然觉悟;
具体看代码吧;
#include<stdio.h> #include<string.h> #include<algorithm> #include<queue> #define N 1001000 using namespace std; struct node { int L, R; }a[N]; char s[N]; int cmp(node p, node q) { if(p.L!=q.L) return p.L<q.L; return p.R<q.R; } int main() { char s0[N]; int n,k, Len; while(scanf("%s", s)!=EOF) { Len=strlen(s); scanf("%d", &n); k=1; for(int i=1; i<=n; i++) { scanf("%s", s0); if(strstr(s, s0)!=NULL) { int pos = 0; int len = 0; while(strstr(s+pos+len, s0)!=NULL) { pos = strstr(s+pos+len, s0)-s; len = strlen(s0); a[k].L=pos; a[k++].R = pos+len-1; } } } sort(a, a+k, cmp); int Max=0; for(int i=2; i<k; i++) { int len1=a[i].R-a[i-1].L-1; int len2=a[i-1].R-a[i].L-1;///如果a[i].R<a[i-1].R; int len = max(len1, len2); if(Max<len) Max=len; } Max=max(Max, a[1].R-1);///与开头和结尾的相比较; Max=max(Len - a[k-1].L, Max); printf("%d\n", Max); } return 0; }
标签:
原文地址:http://www.cnblogs.com/zhengguiping--9876/p/4743166.html