Advertisement
Guest User

стеки 15 номер

a guest
May 21st, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include<iostream>
  2. #include<climits>
  3. #include<stack>
  4. #include<fstream>
  5. using namespace std;
  6.  
  7. ifstream in("input.txt");
  8. ofstream out("output.txt");
  9.  
  10. int main() {
  11.     stack<int>s1;
  12.     stack<int>s2;
  13.     int arr[5];
  14.     int value;
  15.     int max = INT_MIN;
  16.  
  17.     while (in >> value) {
  18.         if (value > max) max = value;
  19.         s1.push(value);
  20.     }
  21.  
  22.     while (!s1.empty())
  23.     {
  24.         int cur;
  25.         cur = s1.top();
  26.         if (cur == max) {
  27.             s1.pop();
  28.             continue;
  29.         }
  30.  
  31.         else s2.push(cur);
  32.         s1.pop();
  33.     }
  34.     while (!s2.empty()) {
  35.         out << s2.top() << ' ';
  36.         s2.pop();
  37.     }
  38.     out.close();
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement