Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
115522 | 彭士宝 | 31回文字符串II | C++ | Wrong Answer | 0 MS | 276 KB | 1101 | 2025-03-31 15:24:30 |
#include <iostream> #include <string> using namespace std; // 函数:判断以某个中心点扩展的回文子串 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; }
------Input------
aa
------Answer-----
No
------Your output-----
Yes