hdu 5818
来源:互联网 发布:全球淘宝下载 编辑:程序博客网 时间:2024/06/07 20:13
#include <iostream>#include <cstdio>#include <string.h>#include <algorithm>#include <map>#include <queue>#include <stdlib.h>#include <cmath>#include <vector>#include <stack>#define clr(x) memset(x,0,sizeof(x))#define clr2(x) memset(x,INF,sizeof(x))#define clr3(x) memset(x,-INF,sizeof(x))#define INF 0x3f3f3f3f#define MAXN 100010#define MAXM 100010#define pb(x) push_back(x)#define ll long long#define ull unsigned long longusing namespace std;int belong;int num[MAXN];int Case=0;int n,idt;char obj[10],obj2[10];int vis[MAXN];struct Node{ int num,id;} tt;stack<Node> a,b,c;void PUSH(){ scanf("%s%d",obj,&tt.num); tt.id=idt; if (obj[0]=='A') a.push(tt); else b.push(tt); idt++;}void POP(){ scanf("%s",obj); if (obj[0]=='A') { if (!a.empty()) { Node temp=a.top(); a.pop(); printf("%d\n",temp.num); } else { Node temp=c.top(); c.pop(); printf("%d\n",temp.num); } } else { if (!b.empty()) { Node temp=b.top(); b.pop(); printf("%d\n",temp.num); } else { Node temp=c.top(); c.pop(); printf("%d\n",temp.num); } }}stack <Node> d;void MERGE(){ scanf("%s%s",obj,obj2); while ( !a.empty() && !b.empty() ) { Node ta=a.top(); Node tb=b.top(); if (ta.id>tb.id) { d.push(ta); a.pop(); } else { d.push(tb); 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(); }}void solve(){ char s[11]; clr(vis); printf("Case #%d:\n",++Case); for (int i=1; i<=n; i++) { scanf("%s",s); if (s[0]=='p' && s[1]=='u') PUSH(); if (s[0]=='p' && s[1]=='o') POP(); if (s[0]=='m') MERGE(); }}int main(){ while (scanf("%d",&n) && n) solve(); return 0;}
0 0
- hdu 5818
- HDU 5818 模拟
- hdu 5818 Joint Stacks
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- 密码显示隐藏符号格式会变
- hdu 5828
- Android进阶知识点(ViewPager,Fragment argument )
- LVS源码剖析-init
- javascript技术难点(三)之this、new、apply和call详解
- hdu 5818
- spark.mllib源码阅读-优化算法1-Gradient
- 回答阿里社招面试如何准备,顺便谈谈对于Java程序猿学习当中各个阶段的建议
- qos实现之tc流量控制
- matcaffe错误:Invalid MEX-file: caffe.mexa64,x86_64-linux-gnu/libstdc++.so.6
- 常见Android面试题及答案(详细整理)
- 快速排序-Java实现
- hdu 5800
- Python脚本在crontab定时任务中无法运行,但是对应脚本手动执行成功