Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
44129 | 刁泓烨 | 最长回文子串 | C++ | Accepted | 2 MS | 276 KB | 524 | 2023-02-02 13:32:47 |
#include<iostream> #include<cstring> #include<stdio.h> using namespace std; const int N=1e3+10; int dp[N][N]; int main() { string str; getline(cin,str); int res=0; int n=str.length(); for(int i=0;i<n;i++) { int l=i-1,r=i+1; while(l>=0 && r<n && str[l]==str[r]){ l--,r++; }res=max(res,r-l-1); l=i,r=i+1; while(l>=0 && r<n && str[l]==str[r]){ l--,r++; } res=max(res,r-l-1); } cout<<res; return 0; }