{ fp } {* * Problem : SUBSTR * Contest : UOI-2006 (Dnepropetrovsk) * Type : Solution * Date : April 1, 2006 * Author : Sergey Savchuk * Language : Pascal * Compiler : Free Pascal * Algorithm: Slow solution with read optimization *} Var fi,fo: Text; a:array['a'..'z'] of Longint; buf:array[0..10000] of char; i: longint; ch: char; S:String; ls: byte absolute s; M:String; lm: byte absolute m; Begin Assign(fi,'SUBSTR.DAT'); Reset(fi); SettextBuf(fi,Buf,10000); While not Eof(fi) do Begin inc(i); Read(fi,ch); if ch<'a' Then continue; if a[ch]<>0 Then Delete(S,1,pos(ch,S)); a[ch]:=i; S:=S+ch; if ls>lm Then M:=S End; Assign(fo,'SUBSTR.SOL'); ReWrite(fo); Writeln(fo,M); Close(fo) End.