Time Lapse :1hour 10min 0sec
5678.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| #include<iostream> #include <algorithm> using namespace std; int Palindrome(string &s){ int ret = 1; int len; for(int i=0;i<s.length()-1;i++){ len = 0; while((i-len-1)>=0&&(i+len+1<s.length()) && s[i-len-1]==s[i+len+1]) ++len; ret = ret > (len<<1)+1 ? ret : (len<<1)+1; if(s[i]!=s[i+1]) continue; len = 1; while((i-len)>=0&&(i+len+1<s.length()) && s[i-len]==s[i+1+len]) ++len; ret = ret > len<<1 ? ret : len<<1; } return ret; } int main(int argc, char** argv){ register int test_case; int T; scanf("%d",&T); string str; for(test_case = 1; test_case<=T; test_case++){ cin>>str; printf("#%d %d\n",test_case,Palindrome(str)); } return 0; }
|