标签:class str main pac int public ted false for
//判断输入的字符串是不是可以由子串多次重复构成 #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; }
标签:class str main pac int public ted false for
原文地址:https://www.cnblogs.com/277223178dudu/p/11372282.html