Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
113973 | 石茂诤 | 最长回文子串 | C++ | Accepted | 2 MS | 280 KB | 589 | 2025-03-18 13:30:05 |
#include<iostream> #include<cmath> #include<cstdio> #include<cstring> using namespace std; string str; bool FUN(int left, int right) { int len = (right - left + 1) / 2; for(int i=0; i<len; i++) { if(str[left+i] != str[right-i]) return false; } return true; } int main() { int i,j,max = 1; getline(cin,str); for (int i = 0; i < str.length(); i++) { for (int j = i+1; j < str.length(); j++) { if (FUN(i,j)) { if(max < (j-i+1)) max = j-i+1; } } } cout << max << endl; return 0; }