Advertisement
Infiniti_Inter

stack 74 (7) (IRA)

May 21st, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <string>
  5. #include <algorithm>
  6. #include <stack>
  7. #include <queue>
  8.  
  9. using namespace std;
  10.  
  11.  
  12. ifstream fin("input.txt");
  13.  
  14.  
  15. int main()
  16. {
  17.     /*
  18.     1 2 2 3 3 3 4 4 4 4
  19.     */
  20.     stack<int> s;
  21.     while (fin.peek() != EOF)
  22.     {
  23.         int cur;
  24.         fin >> cur;
  25.         if (s.empty() || s.top() != cur)
  26.             s.push(cur);
  27.     }
  28.     while (!s.empty())
  29.     {
  30.         int cur = s.top();
  31.         s.pop();
  32.         cout << cur << ' ';
  33.     }
  34.     cout << endl;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement