您的位置:首页 > 其它

算法竞赛入门经典3.4 周期串UVa455

2016-07-27 22:57 441 查看
#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; 


 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: