POJ 2406 Power Strings 简单KMP模板 strcmp

http://poj.org/problem?id=2406

只是模板,但是有趣的是一个strcmp的字符串比较函数,学习到了...

↑百度的概念
像 poj1961 但是更简单..主要是告诫我要学习一下str相关的函数,似乎说要学str函数好久了也没有经常用过
代码
 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 #include<algorithm>
 5 #include<cmath>
 6 #include<queue>
 7 using namespace std;
 8 const int maxn=1000010;
 9 const double eps=1e-8;
10 const long long modn=1000;
11 char a[maxn]={};
12 int nex[maxn]={};
13 int n;
14 int doit(){
15     int j=-1,i=0;
16     nex[0]=-1;
17     while(i<n){
18         if(j==-1||a[i]==a[j]){
19             nex[++i]=++j;
20         }else{
21             j=nex[j];
22         }
23     }
24     if(n%(n-nex[n])==0){
25         return n/(n-nex[n]);
26     }
27     return 1;
28 }
29 int main(){
30     while(~scanf("%s",a)){
31         memset(nex,0,sizeof(nex));
32         if(strcmp(a,".")==0){ break; }
33         n=strlen(a);
34         printf("%d
",doit());
35     }
36     return 0;
37 }
View Code
原文地址:https://www.cnblogs.com/137shoebills/p/7786477.html