Facebook
From Stained Pelican, 7 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 242
  1. #include<iostream>
  2. #include<vector>
  3. #include<string>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     vector <int> stos;
  10.     string komenda;
  11.     while (komenda != "END")
  12.     {
  13.         cin >> komenda;
  14.         if (komenda == "PUSH")
  15.         {
  16.             int liczba;
  17.             cin >> liczba;
  18.             stos.push_back(liczba);
  19.             if (stos.size() == 100)
  20.             {
  21.                 cout << "error" << endl;
  22.                 return 0;
  23.             }
  24.         }
  25.         else if (komenda == "POP")
  26.         {
  27.             if (stos.empty() == true)
  28.             {
  29.             cout << "error" << endl;
  30.             return 0;
  31.             }
  32.             else
  33.                 stos.pop_back();
  34.         }
  35.     }
  36.         for (int i = (stos.size())-1; i>=0; i--)
  37.             cout << stos[i] << endl;
  38. }