标签:cin mes 规律 tle name syn code \n 技术
#include <bits/stdc++.h>
using namespace std;
char a[100005];
int nex[100005];
int len;
void get()
{
memset(nex,0,sizeof(nex));
int j=0;
for(int i=2;i<=len;i++)
{
while(j&&a[i]!=a[j+1])
j=nex[j];
if(a[i]==a[j+1])
j++;
nex[i]=j;
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
while(n--)
{
cin>>a+1;
len=strlen(a+1);
get();
int t1=len-nex[len];
if(nex[len]==0)
cout<<len<<"\n";
else if(len%t1==0)
cout<<0<<"\n";
else
cout<<t1-len%t1<<"\n";
}
}
Cyclic Nacklace HDU - 3746 (kmp next数组应用)
标签:cin mes 规律 tle name syn code \n 技术
原文地址:https://www.cnblogs.com/baccano-acmer/p/10043214.html