题解 | #最长回文子串#
最长回文子串
https://www.nowcoder.com/practice/12e081cd10ee4794a2bd70c7d68f5507
#include <bits/stdc++.h> using namespace std; int main(){ string str; getline(cin,str); int x = 0; for(int i = 0;i<str.length()-2;i++){ for(int j = str.length();j>i;j--){ int n = j-i; string str1 = str.substr(i,n); string str2 = str1; reverse(str2.begin(),str2.end()); if( str1 == str2 ) { x=max(x,n); } } }cout << x; }