Advertisement
Guest User

stack(74)

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