L2-008. Longest symmetric substring, longest l2-008

Source: Internet
Author: User

L2-008. Longest symmetric substring, longest l2-008

For a given string, this question requires you to output the maximum length of the symmetric substring. For example, if "Is PAT & TAP into Ric? ", The longest symmetric substring is" s PAT & TAP s ", so you should output 11.

Input Format:

Enter a non-null string of no more than 1000 characters in a row.

Output Format:

Output the maximum length of a symmetric substring in a row.

Input example:

Is PAT&TAP symmetric?

Output example:

11

Time limit 100 ms memory limit 65536 kB code length limit 8000 B discriminant program Standard author Chen Yue
# Include <stdio. h> # include <stdlib. h> # include <string. h> int main () {int I, j, q, k = 0; int count [10001] = {0}; char arr [1001]; int max; gets (arr); if (strlen (arr) = 1) max = 1; else {// The longest string is an odd for (I = 1; I <strlen (arr) -1; I ++) {j = I; q = I; while (arr [-- j] = arr [++ q] & j> = 0 & q <strlen (arr) {count [k] ++ ;} count [k] = count [k] * 2 + 1; k ++;} // The longest string is an even number for (I = 0; I <strlen (arr ); I ++) {j = I; q = I + 1; while (arr [j] = arr [q] & j> = 0 & q <strlen (arr) {j --; q ++; count [k] ++;} count [k] = count [k] * 2; k ++;} max = count [0]; for (I = 1; I <k; I ++) {if (count [I]> max) max = count [I] ;}} printf ("% d", max ); return 0 ;}

 

Related Article

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.