Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uses math;
- type rec = record
- w,ind:longint;
- end;
- var count: array [0..500] of longint;
- pos: array [0..500] of char;
- i,j,sv,n,u,l,h,um,max,delta,e:longint;
- st: array [0..500] of rec;
- s:string;
- a:array[-500..500,-500..500] of byte;
- begin
- readln(n);
- readln(s);
- sv:=0;
- st[0].w:=1;
- for i:=0 to 500 do
- count[i]:=maxlongint;
- for i:=1 to n do
- if s[i]='[' then begin
- inc(sv);
- st[sv].w:=min(st[sv-1].w,count[i-1]);
- st[sv].ind:=i;
- if st[sv].w=st[sv-1].w then begin
- for j:=1 to sv-1 do
- inc(st[j].w,2);
- end;
- end
- else begin
- count[i]:=st[sv].w;
- pos[i]:='r';
- count[st[sv].ind]:=count[i];
- pos[st[sv].ind]:='l';
- dec(sv);
- end;
- max:=-1;
- for i:=1 to n do
- if count[i]>max then max:=count[i];
- e:=1;
- i:=2;
- while e<n do
- begin
- delta:=max-count[e];
- while (count[i]<>count[e]) or (pos[i]<>'r') do
- begin
- inc(count[i],delta);
- inc(i);
- end;
- inc(count[i],delta);
- inc(count[e],delta);
- e:=i+1;
- i:=e+1;
- end;
- fillchar(a,sizeof(a),0);
- h:=-1;
- for i:= 1 to n do
- if count[i]>h then h:=count[i];
- u:=0;
- l:=0;
- um:=maxlongint;
- for i:=1 to n do
- if pos[i]='l' then begin
- if i<>1 then u:=u+((count[i-1]-count[i]) div 2);
- if um>u then um:=u;
- a[u,l+1]:=1;
- a[u,l]:=2;
- for j:=1 to count[i] do
- a[u+j,l]:=3;
- // writeln(u);
- a[count[i]+u+1][l]:=2;
- a[count[i]+u+1][l+1]:=1;
- inc(l);
- end
- else begin
- if i<>1 then u:=u+((count[i-1]-count[i]) div 2);
- if (pos[i-1]='l') and (pos[i]='r') then l:=l+3
- else l:=l;
- a[u][l-1]:=1;
- a[u][l]:=2;
- for j:=1 to count[i] do
- a[u+j][l]:=3;
- a[count[i]+u+1][l]:=2;
- a[count[i]+u+1][l-1]:=1;
- inc(l);
- end;
- for i:=um to um+h+1 do
- begin
- for j:=0 to l+1 do
- begin
- if a[i][j]=0 then write(' ');
- if a[i][j]=1 then write('-');
- if a[i][j]=2 then write('+');
- if a[i][j]=3 then write('|');
- end;
- writeln;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement