字符串应用-密码截取(最长回文子串)
#include<iostream> #include<vector> #include<string> #include<algorithm> using namespace std; int main() { string s; while(cin>>s) { string t(s); reverse(t.begin(),t.end()); int len = t.size(); int maxlen = 0; vector<int> ans(len+1,0); vector<vector<int>> dp(len+1,ans); for(int i=1;i<len;i++) { for(int j=1;j<len;j++) { if(s[i-1]==t[j-1]) dp[i][j] = dp[i-1][j-1]+1; if(dp[i][j]>maxlen) { maxlen = dp[i][j]; } } } cout<<maxlen<<endl; } return 0; }