• API
• FAQ
• Tools
• Archive
SHARE
TWEET

Untitled

sonprao Oct 15th, 2018 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. var  s,kq,t:ansistring;
2. a:array[0..5000,0..5000] of longint;
3. n,i,j,max,k:longint;
4. kt:array['A'..'Z'] of boolean;
5. kt2:boolean;
6. f:text;
7. begin
8.         assign(f,'');reset(f);
10.     a[1][1]:=1;
11.     max:=0;
12.     for i:=1 to 2500 do kq:=kq+'Z';
13.     n:=length(s);
14.     for i:=1 to n do a[i][i]:=1;
15.     fillchar(kt,sizeof(kt),true);
16.     for i:=1 to n do
17.     for j:=i+1 to n do
18.     begin
19.         if (kt2=true) then fillchar(kt,sizeof(kt),true);
20.         kt[s[i]]:=false;
21.         if kt[s[j]]=true then begin kt[s[j]]:=false; a[i][j]:=a[i][j-1]+1; end
22.         else
23.         a[i][j]:=a[i][j-1]-1;
24.         if j<n then kt2:=false;
25.         if j=n then kt2:=true;
26.     end;
27.     for i:=1 to n do
28.     for j:=1 to n do if a[i][j]>max then  max:=a[i][j];
29.     for i:=1 to n do
30.     for j:=i to n do
31.     if a[i][j]=max then
32.     begin
33.          t:=s;
34.          delete(t,j+1,length(s)-j);
35.          delete(t,1,i-1);
36.          if (t<kq) then kq:=t;
37.     end;
38.     write(kq);
39. 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.

Top