Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program Bai077;
- Uses crt;
- Const
- InputFile = 'BRACKETS.INP';
- OutputFile = 'BRACKETS.OUT';
- Var
- f: Text;
- A, Stack: Array [1..10000] of Integer;
- n, TopInd: Integer;
- S: ANSIString;
- Procedure Input;
- Var
- i: Integer;
- Begin
- Assign(f,InputFile);
- Reset(f);
- Readln(f,n);
- For i:=1 to n do
- Read(f,A[i]);
- Close(f);
- End;
- Procedure Init;
- Begin
- TopInd:=0;
- End;
- Procedure Push(i: Integer);
- Begin
- inc(TopInd);
- Stack[TopInd]:=i;
- End;
- Procedure Pop;
- Begin
- If TopInd>=1 then dec(TopInd);
- End;
- Function Top: Integer;
- Begin
- If TopInd>=1 then Top:=Stack[TopInd]
- else Top:=-1;
- End;
- Procedure DecreaseAll;
- Var
- i: Integer;
- Begin
- For i:=1 to TopInd do
- dec(Stack[i],2);
- End;
- Procedure Process;
- Var
- i: Integer;
- Begin
- Init;
- S:='';
- For i:=1 to n do
- Begin
- Push(A[i]);
- S:=S+'(';
- While Top=0 do
- Begin
- Pop; S:=S+')';
- DecreaseAll;
- End;
- End;
- End;
- Procedure Output;
- Begin
- Assign(f,OutputFile);
- Rewrite(f);
- Writeln(f,S);
- Close(f);
- End;
- Begin
- Input;
- Process;
- Output;
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement