SGU_271_Book_Pile

29 篇文章 0 订阅
23 篇文章 0 订阅

PRO IS HERE


双端队列模拟过程即可,很像2013华中网络预赛的某题。。。

好像是D


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<cmath>
#include<vector>
#include<deque>

using namespace std;

#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define nMax 1010
#define inf 0x7fffffff
#define LL long long
#define pb push_back

struct BB{
	char s[5];
	void read(){
		scanf("%s",s);
	}
	void read(char *str){
		sscanf(str,"ADD(%s",s);
		s[strlen(s)-1]='\0';
	}
};
int k;
deque<BB> que;
bool ok;
vector<BB> ans;

void ADD(BB a){
	if(ok) que.push_front(a);
	else que.push_back(a);
	if(que.size() > k ){
		if(ok) {
			ans.push_back(que.back());
			que.pop_back();
		}
		else   {
			ans.push_back(que.front());
			que.pop_front();
		}
	}
	return ;
}

void Rotate(){
	ok ^= true;
}
void POP(){
	if(ok) {
		while(!que.empty()){
			ans.push_back(que.back());
			que.pop_back();
		}
	}else{
		while(!que.empty()){
			ans.push_back(que.front());
			que.pop_front();
		}
	}
}


int main(){
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	int n,m;
	while(~scanf("%d%d%d",&n,&m,&k)){
		while(!que.empty()) que.pop_front();
		ans.clear();
		ok = false;
		BB a;
		for(int i=0;i<n;i++) {
			a.read();
			que.push_back(a);
		}
		while(que.size() > k) {
			ans.push_back(que.back());
			que.pop_back();
		}
		ok ^= true;
		char Cmd[1010];
		for(int i=0;i<m;i++){
			scanf("%s",Cmd);
			if(Cmd[0] == 'A'){
				a.read(Cmd);
				ADD(a);
			}else {
				Rotate();
			}
		}
		POP();
		for(int i=ans.size()-1;i>=0;i--){
			printf("%s\n",ans[i].s);
		}
	}

	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值