题解

Bryson  •  24天前


STL法大好

用两个队列,一个存输入,一个存答案,不难

#include <bits/stdc++.h>
using namespace std;
queue<int>q, s;

int main() {
	int n;
	cin >> n;

	for (int i = 1; i <= n; i++) {

		int x;
		cin >> x;
		q.push(x);
	}

	int i = 1;

	while (!q.empty()) {
		int front = q.front();

		if (i % 2 != 0) {
			q.pop();
			s.push(front);
		} else {
			q.pop();
			q.push(front);
		}
		i++;
	}

	while (!s.empty()) {
		cout << s.front() << " ";
		s.pop();
	}

	return 0;
}


评论:

请先登录,才能进行评论