AcWing 777. 字符串乘方
原题链接
困难
作者:
胜利庄老实人
,
2021-03-13 09:47:56
,
所有人可见
,
阅读 279
#include<iostream>
using namespace std;
int main(){
string s;
while(cin >> s, s != "."){
string s1;
int flag = 0;
for(int i = 0; i < s.size(); ++i){
s1 = s1 + s[i];
string s2;
for(int j = 0; j < s.size(); ++j){
s2 += s1;
if(s2 == s && s2.size() == s.size()){
flag = 1;
cout << j + 1 << endl;
break;
}
}
if(flag == 1)
break;
}
}
return 0;
}
#include<iostream>
using namsespace std;
int main(){
string s;
while(cin >> s, s != "."){
int len = s.size();
for(int i = len; i > 0; -- i){
if(len % i == 0){
int m = n;
string s1 = s.substr(0, m);
string s2;
for(int j = 0; j < n; ++j)
s2 += s1;
if(s2 == s){
cout << n << endl;
break;
}
}
}
}
return 0;
}