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 ;}