POJ 2406 Power Strings
来源:互联网 发布:小米生态链是什么 知乎 编辑:程序博客网 时间:2024/05/19 15:23
Power Strings
Time Limit: 3000MS Memory Limit: 65536KTotal Submissions: 31975 Accepted: 13328
Description
Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "abcdef". If we think of concatenation as multiplication, exponentiation by a non-negative integer is defined in the normal way: a^0 = "" (the empty string) and a^(n+1) = a*(a^n).
Input
Each test case is a line of input representing s, a string of printable characters. The length of s will be at least 1 and will not exceed 1 million characters. A line containing a period follows the last test case.
Output
For each s you should print the largest n such that s = a^n for some string a.
Sample Input
abcdaaaaababab.
Sample Output
143
#include<iostream>#include<cstring>using namespace std;char str[1000005];int next[1000005];void getnext(int len){int i,k;i=0;k=-1;next[0]=-1;while(i<=len){if(k==-1 || str[i]==str[k]){i++;k++;next[i]=k;}else k=next[k];}}int main(){while(cin>>str){if(str[0]=='.') break;int l=strlen(str);getnext(l);if(2*next[l]<l)cout<<"1\n";else{int mod=l%(l-next[l]);if(mod==0)cout<<l/(l-next[l])<<endl;elsecout<<"1\n";}}return 0;}
0 0
- poj 2406 "Power Strings"
- poj 2406 Power Strings
- POJ-2406 Power Strings
- POJ 2406 Power Strings
- poj 2406 Power Strings
- POJ:2406 Power Strings
- poj 2406 Power Strings
- poj 2406 Power Strings
- poj 2406 Power Strings
- POJ 2406 Power Strings
- POJ 2406 - Power Strings
- poj 2406 Power Strings
- poj 2406 Power Strings
- POJ 2406 Power Strings
- POJ 2406 Power Strings
- POJ 2406 Power Strings
- poj 2406 Power Strings
- POJ 2406 Power Strings
- 【STL】POJ 2418---Hardwood Species
- dp+递归_poj_1088
- hdu 1027 Ignatius and the Princess II
- C语言常量与符号常量
- win8.1 64位环境搭建android开发环境
- POJ 2406 Power Strings
- HTML 网页制作
- java数组
- Linux/Ubuntu 安装 Sublime Text 2
- hdu 1032 The 3n + 1 problem
- ocx控件怎样查看里面的接口和方法
- 设备驱动程序网络驱动程序的修改
- hdu 4906 Our happy ending 状态压缩dp
- 【STL标准模板库讲解】