int strStr(char * haystack, char * needle){
if(strlen(needle) == 0)
return 0;
if(strlen(haystack) ==0||strlen(haystack) <strlen(needle))
return -1;
int x=0,y=0,sta=0;
while(x <=strlen(haystack)-strlen(needle)){
    if(haystack[x] == needle[y])
    sta=1;
    while(sta){
        int a=x+1;
        while(a-x<strlen(needle)){
            y+=1;
            if(haystack[a] == needle[y])
            a++;
            else{
                sta=y=0;
                break;
                }
        }
        if(sta)
        return x;
    }
    x++;
    }
return -1;
}

菜鸡是我菜鸡

此文章已被阅读次数:正在加载...更新于