算法竞赛入门经典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;
}
#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;
}
相关文章推荐
- ···C#学习(六)···
- Fluent Interface(流式接口)
- 用python理解web并发模型
- Python [Leetcode 121]Best Time to Buy and Sell Stock
- 【Leetcode】之Reverse Linked List II
- 毕设遇到的乱码总结
- Linux之使用帮助
- 参数的传递
- 新环境部署(linux硬盘挂载项目迁移启动)
- MAC 10.11下APACHE+PHP+MYSQL环境的配置
- mac svn 别名/域名 ip地址映射解决方案
- 2016年华为秋招机试题——1.回文数字判断(100分)
- Sqlite/ FMDB
- 编译安装Zabbix 3.0及分开部署配置详解
- uboot移植——uboot启动回顾
- tomcat启动报错
- int、long、long long
- [16-7-27]每日总结
- python
- java学习之路 之 面向对象编程-面向对象-对象的关联