Run ID:115526
提交时间:2025-03-31 15:33:21
#include <iostream> #include <string> using namespace std; // 函数:判断是否存在长度大于等于2的回文子串 bool hasPalindromeSubstring(const string& s) { int n = s.length(); for (int i = 0; i < n; ++i) { // 检查奇数长度的回文子串(以单个字符为中心) int left = i, right = i; while (left >= 0 && right < n && s[left] == s[right]) { if (right - left + 1 >= 2) { return true; } left--; right++; } // 检查偶数长度的回文子串(以两个字符为中心) left = i, right = i + 1; while (left >= 0 && right < n && s[left] == s[right]) { if (right - left + 1 >= 2) { return true; } left--; right++; } } return false; } int main() { string s; cin >> s; // 输入字符串 if (hasPalindromeSubstring(s)) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }