hdu 1702 ACboy needs your help again
2014-02-22 01:37
330 查看
点击打开链接
题目大意:题目还是比较好理解的,通过给出的是FIFO 还是FILO, 然后再给出输入的数据给出输出结果;通过STL 栈和队列的使用很容易能够把题目解决了。
代码如下:
题目大意:题目还是比较好理解的,通过给出的是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; }
相关文章推荐
- hdu 1022 Train Problem I
- async/task/await
- RAID练习
- POJ 1273 Drainage Ditches
- 人工智能 Java 坦克机器人系列: 神经网络
- socketpair函数
- DDMS启动出现“Failed to initialize Monitor Thread: Unable to establish loopback connection”错误的解决方法
- "fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt"解决方案
- http://home.gongkong.com/profile/blogdetail.aspx?id=2013120610242900001
- Hadoop & Hbase on OSX 10.8 Mountain Lion
- org.codehaus.xfire.XFireRuntimeException: Could not invoke service.. Server returned error code = 404 for URI.. Check server logs for details
- Hypertable中Hyperspace的Failover
- Installation error: INSTALL_FAILED_INSUFFICIENT_STORAGE
- 添加第三方类库造成的linker command failed with exit code 1 (use -v to see invocation)的错误调试
- 在 FlashDevelop 的移动项目 (Adobe AIR) 中使用 ane
- 根据给出的基类Animal和main()函数。
- GTK+2.0-----容器构件GtkContainer
- http://pan.baidu.com/s/1EHK5u#dir
- 等到花儿也谢了的await
- Megacli查看raid磁盘信息