经典的找最长回文字串问题。最快的算法就是manacher(马拉车)算法,可以O(n)出结果。详情见这篇文章。
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<string> #include<cmath> #include<map> #include<set> #include<list> #include<deque> #include<vector> #include<algorithm> #include<stack> #include<queue> #include<cctype> #include<sstream> using namespace std; #define pii pair<int,int> #define LL long long int const double eps=1e-10; const int INF=1000000000; const int maxn=110000+10; char s[maxn],s2[maxn<<1]; int p[maxn<<1]; int main() { //freopen("in2.txt","r",stdin); //freopen("out.txt","w",stdout); while(scanf("%s",&s[1])!=EOF) { int i; memset(p,0,sizeof(p)); for(i=1;s[i]!='