Advertisement
Infiniti_Inter

15 queue

Nov 13th, 2019
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <stack>
  5. #include <queue>
  6. #include <list>
  7.  
  8. using namespace std;
  9.  
  10.  
  11.  
  12. ifstream in("input.txt");
  13. ofstream out("output.txt");
  14.  
  15. // input.txt : 1 -5 2 3 -4 51 -14 -24 1 5
  16.  
  17. int main()
  18. {
  19. queue<int> q;
  20. while (in.peek() != EOF)
  21. {
  22. int cur; in >> cur;
  23. q.push(cur);
  24. }
  25. queue<int> temp;
  26. queue<int> ans;
  27. while (!q.empty())
  28. {
  29. int cur = q.front(); q.pop();
  30. if (cur > 0)
  31. {
  32. ans.push(cur);
  33. out << cur << ' ';
  34. }
  35. else
  36. temp.push(cur);
  37.  
  38. }
  39. while (!temp.empty())
  40. {
  41. int cur = temp.front(); temp.pop();
  42. out << cur << ' ';
  43. ans.push(cur);
  44. }
  45.  
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement