Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
72925 | 冯诚阳 | 最长回文子串 | C++ | Accepted | 3 MS | 288 KB | 577 | 2024-05-14 17:12:41 |
# include<iostream> # include<cstring> # include<cmath> using namespace std; int main(){ string str; int maxLen=1; cin>>str; for(int i=0;i<str.length();i++){ int temp=0; for(int j=str.length()-1;j>i;j--){ if((i+temp<j)&&(str[i+temp]==str[j])) temp++; else{ temp=0; continue ; } if((i+ temp)==(j-1)&&(2*temp+1)>maxLen) maxLen=(2*temp+1); else if((i+ temp)==j&&(2*temp)>maxLen) maxLen=(2*temp); } } cout<<maxLen<<endl; return 0; }