人生来就是要手动打栈的:) [答案可以直接复制版]

蒙自市蒙自一中马晨烨  •  1年前


#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, top1, top2, front, toil, x, y, wash[N], dry[N], dish[N];

void push_into1(int x) {
	wash[++top1] = x;
}

int pop_out1() {
	return wash[top1--];
}

int get_top1() {
	return wash[top1];
}

bool if_empty1() {
	return top1 == 0;
}

int get_size1() {
	return top1;
}

void push_into2(int x) {
	dry[++top2] = x;
}

int pop_out2() {
	return dry[top2--];
}

int get_top2() {
	return dry[top2];
}

bool if_empty2() {
	return top2 == 0;
}

int get_size2() {
	return top2;
}

void push_back(int x) {
	dish[toil++] = x;
}

int pop() {
	return dish[front++];
}

void init() {
	scanf("%d", &n);
	top1 = 0, top2 = 0, front = 1, toil = 1;
	for (int i = 1; i <= n; i++)
		push_back(i);
}

int main() {
	init();
	while (~scanf("%d%d", &x, &y)) {
	//for (int j = 1; j <= 16; j++) {
		//cin >> x >> y;
		if (x == 1) {
			for (int i = 1; i <= y; i++) {
				push_into1(pop());
			}
		} else if (x == 2) {
			for (int i = 1; i <= y; i++) {
				push_into2(pop_out1());
			}
		}
	}
	for (int i = 1; i <= n; i++)
		printf("%d\n", pop_out2());
	return 0;
}//华丽结束:)

评论:

请先登录,才能进行评论