#include #include #include using namespace std;

bool isPalindrome(string s) { int n = s.length(); for (int i = 0; i < n / 2; i++) { if (s[i] != s[n - i - 1]) { return false; } } return true; }

vector findPalindromes(string s) { vector palindromes; int n = s.length(); for (int len = 2; len <= n; len++) { for (int i = 0; i <= n - len; i++) { string subStr = s.substr(i, len); if (isPalindrome(subStr)) { palindromes.push_back(subStr); } } } return palindromes; }

int main() { string s; cin >> s; vector palindromes = findPalindromes(s); for (string palindrome : palindromes) { cout << palindrome << endl; } return 0;

cpp题目描述给定一个字符串输出所有长度至少为2的回文子串。 回文子串即从左往右输出和从右往左输出结果是一样的字符串比如:abbacccdeedccc都是回文字符串。输入格式一个字符串由字母或数字组成。长度500以内。输出格式输出所有的回文子串每个子串一行。子串长度小的优先输出若长度相等则出现位置靠左的优先输出。输入输出样例样例 1输入样例 复制123321125775165561输出样例 复制3

原文地址: https://www.cveoy.top/t/topic/iS89 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录