Reply
A text return string is a string that is the same for both the forward and reverse reads. For example, a "level" or "Noon" is a text return string.
Code (Java)
Public class Huiwen {public static void main (string [] ARGs) {arraylist <string> List = new arraylist <string> (); sums in = new loads (system. in); int A = in. nextint (); While (in. hasnext () {list. add (in. next (); a --; if (a = 0) break;} For (INT I = 0; I <list. size (); I ++) {string S = List. get (I); int maxlen = maxhuiwen (s); system. out. println (maxlen) ;}} public static int maxhuiwen (string) {in T max = 0; If (string = NULL | string = "") return 0; char [] A = string. tochararray (); For (INT I = 0; I <string. length (); I ++) {for (Int J = 0; I + j <string. length () & I-j> = 0; j ++) {if (a [I-j]! = A [I + J]) {break;} If (2 * j + 1> MAX) {max = 2 * j + 1 ;}// even
for (int j = 0; i+j+1 < a.length&&i-j>=0; j++) { if (a[i-j]!=a[i+j+1]) { break; } if (j*2+2>max) { max=j*2+2; } } } return max; //System.out.println(max); }}
Code (C ++)
# Include <cstdio> # include <cstring> # include <string. h> char STR [1000002 + 1200]; int fast (char * P) {int ans = 1; for (INT I = 1; p [I]; ++ I) {int S = I, E = I, T; // skip the same while (P [E + 1] = P [I]) ++ E; I = E; // After skipping the same value, judge while (P [s-1] = P [E + 1]) -- S, ++ E; if (t = e-S + 1)> ans) ans = T;} return ans;} int main () {STR [0] = '$'; int N; scanf ("% d", & N); While (n --) {scanf ("% s", STR + 1); printf ("% d \ n ", fast (STR);} return 0 ;}
I am the dividing line of tiantiao