码迷,mamicode.com
首页 > 其他好文 > 详细

poj 2406 Power Strings

时间:2017-12-23 12:11:58      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:.net   turn   can   names   pow   char   clu   重复   cst   

Power Strings

 POJ - 2406 

题目大意:给定一个字符串长度为n,已知这个字符串是由某个字符串 S 重复 R 次而得到的,求 R 的最大值。

#include<iostream>
#include<cstdio>
#include<cstring>
#define maxn 10000010
using namespace std;
int l,nxt[maxn];
char s[maxn];
void getnxt(){
    int i=0,j=-1;
    nxt[0]=-1;
    while(i!=l){
        if(s[i]==s[j]||j==-1)nxt[++i]=++j;
        else j=nxt[j];
    }
}
int main(){
    while(1){
        scanf("%s",s);
        l=strlen(s);if(l==1&&s[0]==.)return 0;
        getnxt();
        int ans=1;
        if(l%(l-nxt[l])==0)ans=l/(l-nxt[l]);
        printf("%d\n",ans);
    }
}

 

poj 2406 Power Strings

标签:.net   turn   can   names   pow   char   clu   重复   cst   

原文地址:http://www.cnblogs.com/thmyl/p/8092629.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!