Advertisement
elektryk798

ONP

Apr 1st, 2016
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <iostream>
  2. #include <cctype>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int wynik,licz1=0,licz2=0;
  9.     int ile,n=0;
  10.     cout <<"ile znakow?"<<endl;
  11.     cin >>ile;
  12.     char tab[ile];
  13.     for(int i=0;i<ile;i++)
  14.         cin >>tab[i];
  15.     int stos[30]={0};
  16.     for (int i=0;i<ile;i++)
  17.     {
  18.         if (isdigit(tab[i]))
  19.             stos[n++]=tab[i]-'0';
  20.         else
  21.         {
  22.                 licz1=stos[--n];
  23.                 licz2=stos[--n];
  24.                     switch (tab[i])
  25.                     {
  26.                         case '*':
  27.                             stos[n++]=licz2*licz1;
  28.                             break;
  29.                         case '+':
  30.                             stos[n++]=licz2+licz1;
  31.                             break;
  32.                         case '-':
  33.                             stos[n++]=licz2-licz1;
  34.                             break;
  35.                         case '/':
  36.                             stos[n++]=licz2/licz1;
  37.                             break;
  38.                     }
  39.             }
  40.     }
  41.     wynik=stos[0];
  42.     cout <<wynik<<endl;
  43.     return 0;
  44. }
  45.  
  46. /*
  47. 42  *
  48. 43  +
  49. 45  -
  50. 47  /
  51. 48  0
  52. 57  9
  53. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement