2016暑假多校联合---Joint Stacks (STL)
A mergeable stack is a stack with "merge" operation. There are three kinds of operation as follows:
- push A x: insert x into stack A
- pop A: remove the top element of stack A
- merge A B: merge stack A and B
After an operation "merge A B", stack A will obtain all elements that A and B contained before, and B will become empty. The elements in the new stack are rearranged according to the time when they were pushed, just like repeating their "push" operations in one stack. See the sample input/output for further explanation.
Given two mergeable stacks A and B, implement operations mentioned above.
9
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
using namespace std;
struct Node
{
int x;
int t;
};
stack<Node*>A,B,C,D; int main()
{
int N,Case=;
char s[];
char x;
int c;
while(scanf("%d",&N)&&N)
{
printf("Case #%d:\n",Case++);
for(int i=;i<=N;i++)
{
scanf("%s",s);
if(s[]=='u')
{
scanf(" %c",&x);
scanf("%d",&c);
Node* a=new Node();
a->x=c;
a->t=i;
if(x=='A')
A.push(a);
else
B.push(a);
}
else if(s[]=='o')
{
scanf(" %c",&x);
if(x=='A')
{
if(A.empty())
{
printf("%d\n",C.top()->x);
C.pop();
}
else
{
printf("%d\n",A.top()->x);
A.pop();
}
}
else
{
if(B.empty())
{
printf("%d\n",C.top()->x);
C.pop();
}
else
{
printf("%d\n",B.top()->x);
B.pop();
}
}
}
else if(s[]=='e')
{
scanf(" %c",&x);
scanf(" %c",&x);
while(!A.empty()&&!B.empty())
{
if(A.top()->t>B.top()->t)
{
D.push(A.top());
A.pop();
}
else
{
D.push(B.top());
B.pop();
}
}
while(!A.empty())
{
D.push(A.top());
A.pop();
}
while(!B.empty())
{
D.push(B.top());
B.pop();
}
while(!D.empty())
{
C.push(D.top());
D.pop();
}
}
}
}
return ;
}
2016暑假多校联合---Joint Stacks (STL)的更多相关文章
- 2016暑假多校联合---Rikka with Sequence (线段树)
2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...
- 2016暑假多校联合---Windows 10
2016暑假多校联合---Windows 10(HDU:5802) Problem Description Long long ago, there was an old monk living on ...
- 2016暑假多校联合---Substring(后缀数组)
2016暑假多校联合---Substring Problem Description ?? is practicing his program skill, and now he is given a ...
- 2016暑假多校联合---To My Girlfriend
2016暑假多校联合---To My Girlfriend Problem Description Dear Guo I never forget the moment I met with you. ...
- 2016暑假多校联合---A Simple Chess
2016暑假多校联合---A Simple Chess Problem Description There is a n×m board, a chess want to go to the po ...
- 2016暑假多校联合---Another Meaning
2016暑假多校联合---Another Meaning Problem Description As is known to all, in many cases, a word has two m ...
- 2016暑假多校联合---Death Sequence(递推、前向星)
原题链接 Problem Description You may heard of the Joseph Problem, the story comes from a Jewish historia ...
- 2016暑假多校联合---Counting Intersections
原题链接 Problem Description Given some segments which are paralleled to the coordinate axis. You need t ...
- 2016暑假多校联合---GCD
Problem Description Give you a sequence of N(N≤100,000) integers : a1,...,an(0<ai≤1000,000,000). ...
随机推荐
- 爱上MVC3~MVC+ZTree实现对树的CURD及拖拽操作
回到目录 上一讲中,我们学习了如何使用zTree对一棵大树(大数据量的树型结构的数据表,呵呵,名称有点绕,但说的是事实)进行异步加载,今天这讲,我们来说说,如何去操作这棵大树,无非就是添加子节点,删除 ...
- Java final修饰符
final的定义: 在英文层面上,final的意思是"最后的","最终的"意思,在Java中也同样表示出此种含义. final的运用对象: final适用于修饰 ...
- WebClient.DownloadFile(线程机制,异步下载文件)
线程机制(避免卡屏),异步下载文件. 我做网站的监控,WebClient.DownloadFile这个方法是我经常用到的,必要的时候肯定是要从网上下载些什么(WebRequest 也可以下载网络文件, ...
- Reporting Service 没有权限登陆
在配置好Reporting Service之后,登陆Report Mananger( http://localhost/Reports/Pages/Folder.aspx)出现一个异常,本地用户没有权 ...
- JS中实现数组和对象的深拷贝和浅拷贝
数组的拷贝 > 数组的深拷贝,两层 var arr = [[1,2,3],[4,5,6],[7,8,9]]; var arr2 = []; 循环第一层数组 for(var i=0,len=arr ...
- WPF自定义控件与样式(13)-自定义窗体Window & 自适应内容大小消息框MessageBox
一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要内容: 自定义 ...
- JSP网站开发基础总结《八》
JSP的学习总结到本篇已经八篇了,内容比较多,但都是实战,本篇最后为大家介绍一个小效果:百度分页.就是当我们遍历的数据对象较多时,这时我们就会看到了这个效果了,那他是如何实现的呢?下面我们就一起学习一 ...
- Oracle Linux
一. Oracle Linux下载地址 ftp://ftp.linux.org.uk/pub/distributions/enterprise/ 该地址包含Oracle Linux 6以上版本及RHE ...
- Java多线程系列--“基础篇”11之 生产消费者问题
概要 本章,会对“生产/消费者问题”进行讨论.涉及到的内容包括:1. 生产/消费者模型2. 生产/消费者实现 转载请注明出处:http://www.cnblogs.com/skywang12345/p ...
- Request.UrlReferrer 使用
最近有一个功能是反馈统计,然后在反馈建议里面添加是从哪个页面点击过来的,一开始打算做成&url=这种方法加在链接里面然后页面接受参数,后来知道了request.UrlReferrer 知道他可 ...