SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program zad_d;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   SysUtils;
  7.  
  8. const
  9.   N = 100005;
  10.  
  11. var
  12.   a, k: array [1..N] of integer;//Hi baby bon
  13.   s, x: string;
  14.   cnt, i, c: integer;
  15.  
  16. function stack(s: integer): integer;
  17. begin
  18.   inc(cnt);
  19.   a[cnt] := s;
  20. end;
  21.  
  22. begin
  23.   readln(s);
  24.   c := 0;
  25.   cnt := 0;
  26.   for i := 1 to length(s) do begin
  27.     if (ord(s[i]) in [48..57]) then
  28.       stack(StrToInt(s[i]));
  29.     if (s[i] = '+') then begin
  30.       inc(c);
  31.       k[c] := a[cnt - 1] + a[cnt];
  32.       cnt := cnt - 2;
  33.       stack(k[c]);
  34.     end
  35.     else
  36.       if (s[i] = '*') then begin
  37.         inc(c);
  38.         k[c] := a[cnt - 1] * a[cnt];
  39.         cnt := cnt - 2;
  40.         stack(k[c]);
  41.       end
  42.     else
  43.       if (s[i] = '-') then begin
  44.         inc(c);
  45.         k[c] := a[cnt - 1] - a[cnt];
  46.         cnt := cnt - 2;
  47.         stack(k[c]);
  48.       end;
  49.   end;
  50.   for i := 1 to cnt do begin
  51.     write(a[i], ' ');
  52.   end;
  53.   readln;
  54.   readln;
  55. end.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top