mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
Create 2406.cpp
This commit is contained in:
parent
413d7b91e0
commit
3b6c42acbb
39
POJ/2406.cpp
Normal file
39
POJ/2406.cpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
void getfill(char* s,int L,int* f)
|
||||
{
|
||||
//memset(f,0,sizeof(f)); //根据其前一个字母得到
|
||||
for(int i=1;i<L;i++)
|
||||
{
|
||||
int j=f[i];
|
||||
while(j && s[i]!=s[j])
|
||||
j=f[j];
|
||||
f[i+1]=(s[i]==s[j])?j+1:0;
|
||||
}
|
||||
}
|
||||
|
||||
#define MAXLEN 1000100
|
||||
int next[MAXLEN];
|
||||
char buffer[MAXLEN];
|
||||
int main()
|
||||
{
|
||||
while(scanf("%s",buffer)==1)
|
||||
{
|
||||
if(buffer[0]=='.') break;
|
||||
memset(next,0,sizeof(next));
|
||||
int len=strlen(buffer);
|
||||
getfill(buffer,len,next);
|
||||
if(len%(len-next[len])==0)
|
||||
{
|
||||
printf("%d\n",len/(len-next[len]));
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("1\n");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user