Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uses UStack;
- procedure Inp(var somestack: Stack);
- var
- ifp: Text;
- symb: Char;
- begin
- assign(ifp, 'input.txt');
- reset(ifp);
- read(ifp, symb);
- while (symb <> '.') do
- begin
- somestack.push(symb);
- read(ifp, symb);
- end;
- close(ifp);
- end;
- procedure minmax(var tmp: Stack);
- var
- op1, op2: char;
- null, operation: char;
- begin
- operation:= tmp.pop;
- null:= tmp.pop;
- op1:= tmp.pop;
- null:= tmp.pop;
- op2:= tmp.pop;
- null:= tmp.pop;
- case (operation) of
- 'm': begin
- if (op1 < op2) then
- tmp.push(op1)
- else
- tmp.push(op2);
- end;
- 'M': begin
- if (op1 < op2) then
- tmp.push(op2)
- else
- tmp.push(op1);
- end;
- end;
- end;
- procedure Outp(somestack: Stack);
- var
- tmp: Stack;
- symb: char;
- ofp: Text;
- begin
- tmp.Init;
- while not (somestack.isEmpty) do
- begin
- symb:= somestack.pop;
- case (symb) of
- ')','(',',','0'..'9': tmp.push(symb);
- 'm','M': begin
- tmp.push(symb);
- minmax(tmp);
- end;
- end;
- end;
- assign(ofp, 'output.txt');
- rewrite(ofp);
- writeln(ofp, tmp.top);
- close(ofp);
- end;
- var
- mystack: Stack;
- begin
- mystack.Init;
- Inp(mystack);
- Outp(mystack);
- end.
Advertisement
Add Comment
Please, Sign In to add comment