SHARE
TWEET

Untitled

sonprao Oct 16th, 2018 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //uses crt;
  2. var s,t,kq:ansistring;
  3. kt :array['A'..'Z'] of longint;
  4. n,m:array[1..100000000] of longint;
  5. i,j,max,richness,k:longint;
  6. begin
  7.         //clrscr;
  8.     readln(s);
  9.     for i:=1 to 2500 do kq:=kq+'Z';
  10.     max:=0;
  11.     for i:=1 to length(s) do
  12.     begin
  13.         fillchar(kt,sizeof(kt),0);
  14.         richness:=0;
  15.         for j:=i to length(s) do
  16.                 begin
  17.                         if kt[s[j]]=0 then begin  inc(richness); inc(kt[s[j]]); end else
  18.                         if kt[s[j]]=1 then begin  dec(richness); inc(kt[s[j]]); end;
  19.                         if richness > max then max:= richness;
  20.                 end;
  21.     end;
  22.     k:=0;
  23.     for i:=1 to length(s) do
  24.     begin
  25.         fillchar(kt,sizeof(kt),0);
  26.         richness:=0;
  27.         for j:=i to length(s) do
  28.                 begin
  29.                         if kt[s[j]]=0 then begin  inc(richness); inc(kt[s[j]]); end else
  30.                         if kt[s[j]]=1 then begin  dec(richness); inc(kt[s[j]]); end;
  31.                         if richness = max then begin inc(k); m[k]:=i;   n[k]:=j; end;
  32.                 end;
  33.     end;
  34.     for i:=1 to k do
  35.     begin
  36.         t:='';
  37.         for j:=m[i] to n[i] do t:=t+s[j];
  38.         if t<kq then kq:=t;
  39.     end;
  40.     write(kq);
  41. end.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top