hdu 1702 ACboy needs your help again!
2015-08-24 19:46
405 查看
纯栈和队列应用的水题,这么好的水题我以前怎么没发现
#include<iostream> #include<queue> #include<stack> using namespace std; int n; void que() { queue<int>root; for(int i=0;i<n;i++) { string cmd; cin>>cmd; if(cmd=="IN") { int x; cin>>x; root.push(x); } else { if(root.size()) { cout<<root.front()<<endl; root.pop(); } else cout<<"None"<<endl; } } } void sta() { stack<int>root; for(int i=0;i<n;i++) { string cmd; cin>>cmd; if(cmd=="IN") { int x; cin>>x; root.push(x); } else { if(root.size()) { cout<<root.top()<<endl; root.pop(); } else cout<<"None"<<endl; } } } int main() { int t; cin>>t; while(t--) { cin>>n; string cmd; cin>>cmd; if(cmd=="FIFO") que(); else sta(); } return 0; }
相关文章推荐
- 1090. Highest Price in Supply Chain (25) -计层的BFS改进
- 1090. Highest Price in Supply Chain (25) -计层的BFS改进
- POJ2010--Moo University-Financial Aid(优先队列)
- Codeforces Round #317 [AimFund Thanks-Round] (Div. 1)(组合数学+容斥)
- 关键字copy 、retain、assign
- [[NSBundle mainBundle] infoDictionary]
- 利用QPainter绘制各种图形
- SharePoint 2013 - Cross-domain Library
- network namespace 与veth pair
- UNIX SIGIO信号的使用http://blog.csdn.net/msda/article/details/8090748
- AIX配置时间服务器(NTP)
- xcode提示: failed to get the task for process 解决方法
- Contains Duplicate -- leetcode
- dojo的TabContainer竖排摆放tab标签
- UVA 10900 So you want to be a 2n-aire? 2元富翁 (数学期望,贪心)
- solr源码分析之数据导入DataImporter追溯。
- hdu 4585 set + pair
- [LeedCode OJ]#219 Contains Duplicate II
- [LeedCode OJ]#217 Contains Duplicate
- ORA-15081: failed to submit an I/O operation to a disk