Run ID:115524

提交时间:2025-03-31 15:31:21

#include <iostream> #include <string> using namespace std; // 函数:判断一个字符串是否是回文 bool isPalindrome(const string& s, int start, int end) { while (start < end) { if (s[start] != s[end]) { return false; } start++; end--; } return true; } int main() { string s; cin >> s; // 输入字符串 int n = s.length(); bool hasPalindrome = false; // 遍历所有可能的子串 for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { // 子串长度至少为2 if (isPalindrome(s, i, j)) { hasPalindrome = true; break; } } if (hasPalindrome) { break; } } // 输出结果 if (hasPalindrome) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }