Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <stack>
- #include <vector>
- using namespace std;
- int main()
- {
- int n;
- cin >> n;
- queue<int> que;
- stack<int> stk;
- vector<int> vec;
- for (int i = 0; i < n; i++)
- {
- int x;
- cin >> x;
- if (x % 3 == 0)
- {
- que.push(x);
- }
- else
- if (x % 3 == 1) stk.push(x);
- else vec.push_back(x);
- }
- while (!que.empty())
- {
- int x = que.front();
- cout << x << ' ';
- que.pop();
- }
- while (!stk.empty())
- {
- int x = stk.top();
- cout << x << ' ';
- stk.pop();
- }
- for (int i = 0; i < vec.size() / 2; i++)
- {
- cout << vec[i] << ' ' << vec[vec.size() - i-1] << ' ';
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment