awsmpshk

Номер 3 к 21.05, Кузичкин 141 группа

May 20th, 2020
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. #include <stack>
  4. #include <vector>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int n;
  10.     cin >> n;
  11.     queue<int> que;
  12.     stack<int> stk;
  13.     vector<int> vec;
  14.     for (int i = 0; i < n; i++)
  15.     {
  16.         int x;
  17.         cin >> x;
  18.         if (x % 3 == 0)
  19.         {
  20.             que.push(x);
  21.         }
  22.         else
  23.             if (x % 3 == 1) stk.push(x);
  24.             else vec.push_back(x);
  25.     }
  26.     while (!que.empty())
  27.     {
  28.         int x = que.front();
  29.         cout << x << ' ';
  30.         que.pop();
  31.     }
  32.     while (!stk.empty())
  33.     {
  34.         int x = stk.top();
  35.         cout << x << ' ';
  36.         stk.pop();
  37.     }
  38.     for (int i = 0; i < vec.size() / 2; i++)
  39.     {
  40.         cout << vec[i] << ' ' << vec[vec.size() - i-1] << ' ';
  41.     }
  42.     return 0;
  43. }
Add Comment
Please, Sign In to add comment