1.3.3 Calf Flac
It is said that if you give an infinite number of cows an infinite number of heavy-duty laptops (with very large keys), that they will ultimately produce all the world's great palindromes. Your job will be to detect these bovine beauties.
Ignore punctuation, whitespace, numbers, and case when testing for palindromes, but keep these extra characters around so that you can print them out as the answer; just consider the letters `A-Z' and `a-z'.
Find the largest palindrome in a string no more than 20,000 characters long. The largest palindrome is guaranteed to be at most 2,000 characters long before whitespace and punctuation are removed.
PROGRAM NAME: calfflac
INPUT FORMAT
A file with no more than 20,000 characters. The file has one or more lines which, when taken together, represent one long string. No line is longer than 80 characters (not counting the newline at the end).
SAMPLE INPUT (file calfflac.in)
Confucius say: Madam, I'm Adam.
OUTPUT FORMAT
The first line of the output should be the length of the longest palindrome found. The next line or lines should be the actual text of the palindrome (without any surrounding white space or punctuation but with all other characters) printed on a line (or more than one line if newlines are included in the palindromic text). If there are multiple palindromes of longest length, output the one that appears first.
SAMPLE OUTPUT (file calfflac.out)
11 Madam, I'm Adam
{ ID: makeeca1 PROG: calfflac LANG: PASCAL } program calfflac; var ss,s:array[1..20000]of char;i,l,max,x,t:longint;ch:char; a,f:array[1..20000]of integer; begin assign(input,'calfflac.in');reset(input); assign(output,'calfflac.out');rewrite(output); s:='';ss:='';l:=0;i:=0;max:=1; while not eof do begin read(ch); inc(t);ss[t]:=ch; if (ch in ['a'..'z'])or(ch in['A'..'Z'])then begin inc(l);s[l]:=upcase(ch);a[l]:=t;end; end; f[1]:=1; for i:=2 to l do begin f[i]:=1; if (i-f[i-1]-1>0)and(s[i]=s[i-f[i-1]-1])then f[i]:=f[i-1]+2 else if s[i]=s[i-1]then f[i]:=2; if f[i]>f[max]then max:=i; end; writeln(f[max]); l:=max-f[max]+1; for i:=a[l] to a[max]do write(ss[i]);writeln; close(output); end.