Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
115524 | 彭士宝 | 31回文字符串II | C++ | Wrong Answer | 1 MS | 276 KB | 951 | 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; }
------Input------
aa
------Answer-----
No
------Your output-----
Yes