蓝桥杯模拟赛,求一个串的最长回文子串
#include <iostream> #include<algorithm> #include <stdio.h> #define ll long long /* run this program using the console pauser or add your own getch, system("pause") or input loop */ using namespace std; char s[100000]; int malache() { int res=0; for(int i=1;s[i];i++) { int l=i; int r=i; while(s[i]==s[r+1]) { r++; } i=r; while(s[l-1]==s[r+1]) { r++; l--; } if(res<r-l+1) { res=r-l+1; } } return res; } int main(int argc, char *argv[]) { s[0]='$'; gets(s+1); cout<<malache(); return 0; }