Advertisement
myname0

практика_стек_и_очередь_3

Jun 30th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <queue>
  2. #include <stack>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. int main()
  9. {
  10.     ifstream in ("input.txt");
  11.     ofstream out("output.txt");
  12.  
  13.     queue <int> myQueue;
  14.     stack <int> myStack;
  15.     int tmp;
  16.     while(in >> tmp)
  17.     {
  18.         if (tmp > 0)
  19.             myQueue.push(tmp);
  20.     }
  21.     while(!myQueue.empty())
  22.     {
  23.         if(myQueue.front() % 2 != 0)
  24.             myStack.push(myQueue.front());
  25.         myQueue.pop();
  26.     }
  27.     while(!myStack.empty())
  28.     {
  29.         out << myStack.top() << " ";
  30.         myStack.pop();
  31.     }
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement