KMP模板


//KMP算法模板
#include
#include

using namespace std;

char s[1005],str[105];
int Next[105];

void Get_KMP()
{
    int m = strlen(str);
    int i=0,j=-1;
    Next[0] = -1;
    while(i=m) return i-m;
    else return -1;
}

int main()
{
    ios::sync_with_stdio(false);
    cin >> s >> str;
    Get_KMP();
    printf("%d\n",KMP());
    return 0;
}
//exKMP模板
#include

using namespace std;

const int MAXN = 1e4 + 10;
int Next[MAXN],extend[MAXN];
string str,s;

void Get_Next()
{
    int now = 0;
    Next[0] = str.size();
    while(str[now]==str[1+now] && now+1> s >> str;
    exKMP();
    for(int i=0; i
//manacher模板
#include
#include

using namespace std;

const int MAXN = 22e6 + 10;
int hw[MAXN];
char s[MAXN],str[MAXN/2];

void change()
{
    s[0] = s[1] = '#';
    int n = strlen(str);
    for(int i=1; i<=n; i++)
    {
        s[i*2] = str[i-1];
        s[i*2+1] = '#';
    }
    s[n*2+2] = 0;
}

void manacher()
{
    change();
    int maxright=0,mid;
    int n = strlen(s);
    for(int i=1; imaxright)
        {
            maxright = i + hw[i];
            mid = i;
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin >> str;
    manacher();
    int ans = 0;
    int n = strlen(s);
    for(int i=2; i ans) ans = hw[i];
    }
    cout<< ans-1 <