hdu 1702 ACboy needs your help again
来源:互联网 发布:淘宝联盟批量链接工具 编辑:程序博客网 时间:2024/05/16 23:38
点击打开链接
题目大意:题目还是比较好理解的,通过给出的是FIFO 还是FILO, 然后再给出输入的数据给出输出结果;通过STL 栈和队列的使用很容易能够把题目解决了。
代码如下:
#include <iostream>#include <string>#include <queue>#include <stack>using namespace std;void que_solve(int n){queue<int>Q;char s[10];int a;while(n--){cin>>s;if(!strcmp(s, "IN")){cin>>a;Q.push(a);}else if(!strcmp(s, "OUT")){if(Q.empty())cout<<"None"<<endl;else{cout<<Q.front()<<endl;Q.pop();}}}}void sta_solve(int n) { stack<int>S; char s[10]; int a; while(n--) { cin>>s; if(!strcmp(s, "IN")) { cin>>a ; S.push(a); } else if(!strcmp(s, "OUT")) { if(S.empty()) cout<<"None"<<endl; else { cout<<S.top()<<endl; S.pop(); } } } } int main() { int n; while(cin>>n) { while(n--) { int m; char str[100]; cin>>m>>str; if(!strcmp(str,"FIFO")) que_solve(m); else if(!strcmp(str,"FILO")) sta_solve(m); else cout<<"error"<<endl; } } return 0; }
0 0
- HDU 1702 ACboy needs your help again!
- HDU 1702 ACboy needs your help again!
- hdu 1702 ACboy needs your help again!
- HDU-ACboy needs your help again!-1702
- hdu 1702 ACboy needs your help again
- HDU 1702 ACboy needs your help again!
- HDU-1702-ACboy needs your help again!
- HDU 1702 ACboy needs your help again!
- hdu---1702ACboy needs your help again!
- HDU - 1702 ACboy needs your help again!
- HDU 1702 ACboy needs your help again!
- HDU 1702 ACboy needs your help again!
- hdu 1702 ACboy needs your help again!
- hdu 1702 ACboy needs your help again!
- hdu 1702 ACboy needs your help again!
- hdu 1702 ACboy needs your help again!
- hdu 1702 ACboy needs your help again!
- HDU - 1702 ACboy needs your help again!
- android,HttpPost发送数据到服务器
- 特征变换以及维度下降——LDA VS PCA
- 关于公交系统中运用NFC-TSM技术进行移动支付的解决案例浅析
- 正则表达式(二)
- 详解Cocos2d-X中宏CC_DLL
- hdu 1702 ACboy needs your help again
- Linux vsftp服务的安装
- POJ 1005 I Think I Need a Houseboat
- hdu 2044 (水题)
- 二分总结一 二分法试解 POJ1064
- Linux vi编辑器的基本命令
- ubuntu13.10 多系统安装
- Linux 搭建svn服务器
- 利用反射泛型编写一个通用Dao