my code stock.com

Search

Snippet options

Download: Download snippet as 133-calf-flac.pas.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

{
 ID:leaspos1
 PROG:calfflac
 LANG:PASCAL
}
type
                int=longint;
 
var
                Temp,Rpos,Vpos,Len,Max,Rl,Rr:int;
                s,t:array[1..200000] of char;
                pos:array[1..200000] of int;
                ts,tts:string;
                ch:char;
 
procedure init();
                function pand(x:char):int;
                begin
                        if ((x>='a')and(x<='z')) then exit(1) 
                        else 
                         if ((x>='A') and(x<='Z')) then exit(2)
                         else
                          exit(3);
                end;
 
                procedure make(x:char);
                begin
                                Temp:=pand(x);
                                if Temp=1 then
                                begin
                                                inc(Rpos);  inc(Vpos);
                                                s[Vpos]:=x; t[Rpos]:=x;
                                                pos[Vpos]:=Rpos;
                                end
                                 else 
                                  if Temp=2 then
                                  begin
                                                inc(Rpos);                               inc(Vpos);
                                                s[vpos]:=chr(ord(x)-ord('A')+ord('a'));  t[rpos]:=x;
                                                pos[Vpos]:=Rpos;
                                  end
                                   else
                                   begin
                                                inc(Rpos);
                                                t[Rpos]:=x;
                                   end;
                end;
 
var
                i:int;
        
begin
                assign(input,'calfflac.in');reset(input);
                assign(output,'calfflac.out');rewrite(output);
                Rpos:=0;Vpos:=0;Len:=0;
                read(ts);
                for i:=1 to length(ts) do
                 make(ts[i]);
                while not eof do
                begin
                        readln;
                        inc(Rpos);t[Rpos]:=chr(1);
                        read(ts);
                        for i:=1 to length(ts) do 
                         make(ts[i]);
                end;
                inc(Rpos);t[Rpos]:=chr(1);
end;
 
procedure main();
        procedure extend(l,r:int);
        begin
                        if (l-1>=1)and(r+1<=len)and(s[l-1]=s[r+1]) then
                         extend(l-1,r+1)
                         else
                         begin
                                if r-l+1>max then
                                begin
                                                Rl:=l;
                                                Rr:=r;
                                                max:=r-l+1;
                                end;
                                exit;
                         end;
        end;
 
var
                i:int;
 
begin
                Len:=Vpos;
                for i:=1 to len-1 do
                begin
                        extend(i,i);
                        if s[i]=s[i+1] then
                         extend(i,i+1);
                end;
end;
 
procedure print();
var
                i:int;
 
begin
                writeln(max);   
                for i:=pos[Rl] to pos[Rr] do
                 if ord(t[i])=1 then 
                   writeln
                   else write(t[i]);
                writeln;
                close(input);close(output);
end;
 
begin
                init();
                main();
                print();
end.

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.