题目描述
//纯暴力
C++ 代码
#include<iostream>
using namespace std;
int main() {
string s1;
while (cin >> s1) {
if (s1 != ".") {
int l = s1.length(),sum=0;
for (int i = 1; i <=l/2; i++) {//最多遍历到一半的位置
if (s1.substr(i, i) == s1.substr(0, i)) {//如果从0到当前长度的子串与下一个相等长度的子串相等
sum = (l / (i));
for (int j = 0; j < l - i; j+=i) {//遍历字符串,若存在不等的子串则说明找到的子串并不是正确的
if (s1.substr(0, i) == s1.substr(j + i, i))continue;
else {
sum = 0; break;
}
}
}
if (sum) {
cout << sum << endl;
break;
}
//cout << s1.substr(0, i) << " != " << s1.substr(i, i)<<endl;
}
if (!sum)cout <<1<<endl;
}
else break;
}
return 0;
}