| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
实测strstr比KMP快俺用的网上粘的KMP
int KMP(char *S,char *T)//S[]是主串,T[]是匹配串
{
int IS,IP,i=0,j;
int fail[M]={-1};
IS=strlen(S);
IP=strlen(T);
for(j=1;j<IP;j++)
{
for(i=fail[j-1];i>=0&&T[i+1]!=T[j];i=fail[i]);
fail[j]=((T[i+1]==T[j])? i+1:-1);
}
for(i=j=0;i<IS&&j<IP;i++)
if(S[i]==T[j]) j++;
else if(j) j=fail[j-1]+1,i--;
return j==IP? i-IP:-1;
}
5697151 linmeng 3080 Accepted 156K 0MS C++ 2250B 2009-08-19 15:05:41
5697127 linmeng 3080 Accepted 156K 16MS C++ 2245B 2009-08-19 15:03:18
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator