Beispiel #1
0
int main(){
    int t, i, palin, alin;
    scanf("%d", &t);
    while(t--){
        palin=alin=1;
        scanf("%s", P);
        n = m = strlen(P);
        for(i=0; i<m; i++) {
            T[i]=P[m-i-1];
            if(T[i]!=P[i]) palin=0;
        }
        kmpPreprocess();
        kmp();

        if(maxj!=-1){
            for(i=0; i< (n-maxj)/2; i++) {
                if(P[maxj+i]!=P[n-i-1]) {
                    alin=0;
                    break;
                }
            }
        } else alin=0;

        if(alin) printf("alindrome\n");
        else if(palin) printf("palindrome\n");
        else printf("simple\n");
    }
    return 0;
}
Beispiel #2
0
int main(){
    strcpy(T, "asdhasdhejasdasdhejasdasd");
    strcpy(P, "hej");
    
    n = 25; m = 3;

    kmpPreprocess();
    kmpSearch();

    return 0;
}
Beispiel #3
0
int main(){
    int t;
    scanf("%d", &t);
    while(t--){
        scanf("%s", P);
        m = strlen(P);
        n = 2*m;
        strcpy(T, P);
        strcat(T, P);
        kmpPreprocess();
        kmp();
        printf("%d\n", occI[1]);
        if(t) printf("\n");
    }
    return 0;
}
int kmp(char *str, char *substr)
{
    int i=0, j=0, count = 0;
    const int n = strlen(str);
    const int m = strlen(substr);

	kmpPreprocess(substr);
    while (i<n)
    {
        while (j>=0 && str[i]!=substr[j])
            j=b[j];

        i++;
        j++;

        if (j==m)
        {
            count++;
            j=b[j];
        }
    }
    return count;
}