Maximum retrieval Length

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.