Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
27332 | 晁老师测试用 | 最长回文子串 | C++ | Accepted | 4 MS | 740 KB | 589 | 2022-06-02 17:39:50 |
#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; }