You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
557 B
C++
24 lines
557 B
C++
#include <cstdio>
|
|
#include <cstring>
|
|
using namespace std;
|
|
const int N = 1e5 + 5;
|
|
char str[N];
|
|
int nxt[N], T;
|
|
int main()
|
|
{
|
|
nxt[0] = -1;
|
|
scanf("%d", &T);
|
|
while (T--)
|
|
{
|
|
scanf("%s", str);
|
|
int len = strlen(str);
|
|
for (int i = 0, j = -1; i < len;)
|
|
if (~j && str[j] != str[i])
|
|
j = nxt[j];
|
|
else
|
|
nxt[++i] = ++j;
|
|
int ans = len - nxt[len];
|
|
printf("%d\n", (len % ans == 0 && ans != len) ? 0 : ans - len % ans);
|
|
}
|
|
return 0;
|
|
} |