章三习题4——UVA 455
2017-02-27 00:34
459 查看
然后用了之前kmp的一个思想
#include <iostream> #include <cstdio> #include <cstring> using namespace std; #define maxn 100 char s[maxn]; int Next[maxn]; void GetNext(char *p) { int k=-1; Next[0]=-1; int slen=strlen(p); int i=0; while(i<slen) { if(k==-1||p[k]==p[i]) { k++; i++; Next[i]=k; } else k=Next[k]; } } int main() { int T; scanf("%d",&T); int n; while(T--) { scanf("%s",s); GetNext(s); int slen=strlen(s); int h=slen-Next[slen]; if(Next[slen]%h==0) printf("%d\n",h); else printf("%d\n",slen); if(T>=1) printf("\n"); } return 0; }
相关文章推荐
- 章三习题4——UVA 455
- 章三习题4——UVA 455
- 章三习题4——UVA 455
- 章三习题4——UVA 455
- 章三习题4——UVA 455
- 章三习题4——UVA 455
- 章三习题4——UVA 455
- 章三习题1——UVA 1585
- 章三习题3——UVA 1225
- 章三习题8——UVA 202 Repearing Decimals
- 章三习题3——UVA 1225
- 章三习题8——UVA 202 Repearing Decimals
- 算法竞赛入门经典(刘汝佳)习题3-4 UVa455
- 章三习题3——UVA 1225
- 章三习题8——UVA 202 Repearing Decimals
- 习题3-4 UVa455 Periodic Strings
- 章三习题3——UVA 1225
- 章三习题8——UVA 202 Repearing Decimals
- 习题3-4 Periodic Strings UVa455
- 章三习题3——UVA 1225