POJ 2406-巧用next数组
2017-07-26 15:47
190 查看
原题
这道题我还没弄懂 但是看了看题解把代码写出来并且A掉了…
这道题我还没弄懂 但是看了看题解把代码写出来并且A掉了…
#include<cstdio> #include<iostream> #include<cstring> using namespace std; int n,next[10000010]; char s[10000010]; void get_next(const char s[],int next[]){ next[0]=0; for(int i=1,k=0;i<n;++i){ while(k>0&&s[k]!=s[i])k=next[k-1]; if(s[k]==s[i])k++; next[i]=k; } return ; } int main(){ scanf("%s",s); while(s[0]!='.'){ n=strlen(s); get_next(s,next); // //cout<<next[n-1]; if(n%(n-next[n-1])==0)printf("%d\n",n/(n-next[n-1])); else printf("1\n"); scanf("%s",s); } return 0; }
相关文章推荐
- POJ 2406(KMP next数组性质)
- poj 2406 Power Strings(kmp next数组的应用)
- poj 2406 kmp算法巩固之next数组的再理解
- POJ - 2406 Power Strings(next数组)
- poj 2406 Power Strings KMP的next数组的应用
- poj 2406 Power Strings[kmp,next数组的应用]
- POJ 2406 KMP算法next数组理解
- POJ 2406 KMP next数组的应用
- POJ 2406 KMP next数组的应用
- POJ 2406 Power Strings(next数组应用)
- 【next数组应用】POJ 2406 Power Strings
- POJ 2406 Power Strings KMP算法之next数组的应用
- poj 2406 Power Strings (kmp 中 next 数组的应用||后缀数组)
- POJ 2406 Power Strings next数组循环节应用、
- POJ - 2406_Power Strings _kmp算法next数组的应用
- POJ - 2406 Power Strings —— next数组求循环节
- POJ 2406 Power Strings (KMP next数组应用)
- poj-2406 kmp中的next数组应用
- POJ 2406 Power Strings 1961的简化版,kmp的next数组的应用
- POJ 2406 Power Strings (kmp next数组)