Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  123
Language: PASCAL
Code:
var  
        s1,s,ss,ch:ansistring;  
        i,j,k,ans,max,kk,sum,kkk:longint;  
        a:array[0..50000] of longint;  
        bz:array[0..100000] of boolean;  
begin  
        while not eof do  
        begin  
                readln(ch);  
                s1:=s1+ch;  
                inc(kkk,length(ch));  
                bz[kkk]:=true;  
        end;  
        ss:=s1;  
        s1:=lowercase(s1);  
        s:='#';  
        for i:=1 to length(s1) do  
                if s1[i] in ['a'..'z'] then//每个之间加上#,可奇偶的回文都可以判断。  
                begin  
                        s:=s+s1[i]+'#';  
                        inc(k);  
                        a[k]:=i;  
                end;  
        for i:=1 to length(s) do  
                for j:=1 to 2000 do//最长就是2000  
                        if (i-j>0)and(i+j<=length(s)) and (s[i-j]=s[i+j]) then  
                        begin  
                                inc(ans);  
                                if ans>max then  
                                begin  
                                        max:=ans;  
                                        k:=i-j;  
                                        kk:=i+j;  
                                end;  
                        end  
                        else  
                        begin  
                                ans:=0;  
                                break;  
                        end;  
        writeln(max);  
        for i:=a[k div 2+1] to a[kk div 2] do//输出  
        begin  
                write(ss[i]);  
                if bz[i] then writeln;  
        end;  
end.  
Comments: