Advertisement
Guest User

Untitled

a guest
Mar 11th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. uses math;
  2.  
  3. type rec = record
  4.     w,ind:longint;
  5. end;
  6.  
  7. var count: array [0..500] of longint;
  8.     pos: array [0..500] of char;   
  9.     i,j,sv,n,u,l,h,um,max,delta,e:longint;
  10.     st: array [0..500] of rec;
  11.     s:string;
  12.     a:array[-500..500,-500..500] of byte;
  13. begin
  14.     readln(n);
  15.     readln(s);                          
  16.     sv:=0;
  17.     st[0].w:=1;
  18.     for i:=0 to 500 do
  19.         count[i]:=maxlongint;
  20.   for i:=1 to n do
  21.         if s[i]='['     then    begin
  22.                                     inc(sv);
  23.                                     st[sv].w:=min(st[sv-1].w,count[i-1]);
  24.                                     st[sv].ind:=i;
  25.                                     if st[sv].w=st[sv-1].w  then    begin
  26.                                                                    
  27.                                                                     for j:=1 to sv-1 do
  28.                                                                         inc(st[j].w,2);
  29.                                                                            
  30.                                                                     end;
  31.                                                                                                                        
  32.                                 end
  33.                        else     begin
  34.                                     count[i]:=st[sv].w;
  35.                                     pos[i]:='r';
  36.                                     count[st[sv].ind]:=count[i];
  37.                                     pos[st[sv].ind]:='l';
  38.                                     dec(sv);
  39.                                 end;
  40.  
  41.     max:=-1;
  42.     for i:=1 to n do
  43.         if count[i]>max then max:=count[i];
  44.  
  45.     e:=1;
  46.     i:=2;
  47.     while e<n do
  48.         begin
  49.             delta:=max-count[e];
  50.  
  51.             while (count[i]<>count[e]) or (pos[i]<>'r') do
  52.                 begin
  53.                     inc(count[i],delta);
  54.                     inc(i);
  55.                 end;
  56.             inc(count[i],delta);
  57.             inc(count[e],delta);
  58.  
  59.             e:=i+1;
  60.             i:=e+1;
  61.         end;
  62.  
  63.     fillchar(a,sizeof(a),0);
  64.     h:=-1;
  65.     for i:= 1 to n do
  66.         if count[i]>h then h:=count[i];
  67.     u:=0;
  68.     l:=0;
  69.     um:=maxlongint;
  70.  
  71.     for i:=1 to n do
  72.         if pos[i]='l'   then    begin
  73.                                     if i<>1 then u:=u+((count[i-1]-count[i]) div 2);
  74.                                     if um>u then um:=u;
  75.                                     a[u,l+1]:=1;
  76.                                     a[u,l]:=2;
  77.                                     for j:=1 to count[i] do
  78.                                         a[u+j,l]:=3;
  79.                                 //  writeln(u);
  80.                                     a[count[i]+u+1][l]:=2;
  81.                                     a[count[i]+u+1][l+1]:=1;
  82.                                     inc(l);
  83.                                 end
  84.  
  85.                          else   begin
  86.                                         if i<>1 then u:=u+((count[i-1]-count[i]) div 2);
  87.  
  88.                                     if (pos[i-1]='l') and (pos[i]='r')  then    l:=l+3
  89.                                                                         else    l:=l;
  90.                                                                    
  91.                                     a[u][l-1]:=1;
  92.                                     a[u][l]:=2;
  93.                                     for j:=1 to count[i] do
  94.                                         a[u+j][l]:=3;
  95.  
  96.                                     a[count[i]+u+1][l]:=2;
  97.                                     a[count[i]+u+1][l-1]:=1;
  98.                                     inc(l);
  99.  
  100.                                 end;
  101.  
  102.     for i:=um to um+h+1 do
  103.         begin
  104.             for j:=0 to l+1 do
  105.                 begin
  106.                     if a[i][j]=0 then write(' ');
  107.                     if a[i][j]=1 then write('-');
  108.                     if a[i][j]=2 then write('+');
  109.                     if a[i][j]=3 then write('|');
  110.                 end;
  111.             writeln;
  112.         end;             
  113.            
  114. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement