Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

实测strstr比KMP快

Posted by linmeng at 2009-08-19 15:08:14 on Problem 3080
俺用的网上粘的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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator