- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- int i;
- int n;
- int a,b,c;
- string s;
- cout<<"please input the string"<<endl;
- cin>>s;
- n=s.length();
- for(i=1;i<=n;i++)
- {
- if(n%i==0)
- {
- a=n/i;
- for(b=1;b<=i;b++)
- {
- for(c=1;c<=a-1;c++)
- {
- if(s[b-1]!=s[b+c*i-1])
- {
- goto here;
- }
- }
- }
- cout<<i<<endl;
- goto here1;
- }
- here:
- ;
- }
- here1:
- ;
- return 0;
- }
算法竞赛入门经典3.4 周期串UVa455
最新推荐文章于 2019-07-20 08:34:06 发布
本文介绍了一个简单的C++程序,用于检测输入字符串的周期性特征。通过遍历字符串长度的所有可能因子,程序判断是否存在重复模式,并输出所有可能的周期长度。
14万+

被折叠的 条评论
为什么被折叠?



