t1nman

Prac_mM

May 28th, 2012
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.51 KB | None | 0 0
  1. uses UStack;
  2.  
  3. procedure Inp(var somestack: Stack);
  4. var
  5.     ifp: Text;
  6.     symb: Char;
  7. begin
  8.     assign(ifp, 'input.txt');
  9.     reset(ifp);
  10.     read(ifp, symb);
  11.     while (symb <> '.') do
  12.     begin
  13.         somestack.push(symb);
  14.         read(ifp, symb);
  15.     end;
  16.     close(ifp);
  17. end;
  18.  
  19. procedure minmax(var tmp: Stack);
  20. var
  21.     op1, op2: char;
  22.     null, operation: char;
  23. begin
  24.     operation:= tmp.pop;
  25.     null:= tmp.pop;
  26.     op1:= tmp.pop;
  27.     null:= tmp.pop;
  28.     op2:= tmp.pop;
  29.     null:= tmp.pop;
  30.    
  31.     case (operation) of
  32.         'm': begin
  33.                  if (op1 < op2) then
  34.                     tmp.push(op1)
  35.                  else
  36.                     tmp.push(op2);
  37.              end;
  38.         'M': begin
  39.                  if (op1 < op2) then
  40.                     tmp.push(op2)
  41.                 else
  42.                     tmp.push(op1);
  43.              end;
  44.     end;
  45. end;
  46.  
  47.  
  48.  
  49. procedure Outp(somestack: Stack);
  50. var
  51.     tmp: Stack;
  52.     symb: char;
  53.     ofp: Text;
  54. begin
  55.     tmp.Init;
  56.     while not (somestack.isEmpty) do
  57.     begin
  58.         symb:= somestack.pop;
  59.         case (symb) of
  60.             ')','(',',','0'..'9': tmp.push(symb);
  61.             'm','M': begin
  62.                         tmp.push(symb);
  63.                         minmax(tmp);
  64.                      end;
  65.         end;
  66.     end;
  67.  
  68.     assign(ofp, 'output.txt');
  69.     rewrite(ofp);
  70.     writeln(ofp, tmp.top);
  71.     close(ofp);
  72. end;
  73.  
  74. var
  75.     mystack: Stack;
  76. begin
  77.     mystack.Init;
  78.     Inp(mystack);
  79.     Outp(mystack);
  80. end.
Advertisement
Add Comment
Please, Sign In to add comment