//判断输入的字符串是不是可以由子串多次重复构成 #include<iostream> #include<string> using namespace std; class Solution { public: bool repeated(string s) { int n = s.size(); string temp1 = ""; string temp2 = ""; for (int i = 2; i <= n; ++i) { if (n % i == 0) { int length = n / i; temp1 = string(s.begin(), s.begin() + length); for (int j = 0; j < i; ++j) temp2 += temp1; } if (temp2 == s) cout << temp1 << endl; return true; temp2 = ""; } return false; } }; int main() { string str; cin >> str; //Solution().repeated(str); cout << Solution().repeated(str) << endl; system("pause"); return 0; }
原文地址:https://www.cnblogs.com/277223178dudu/p/11372282.html
时间: 2024-11-13 06:15:38