HDU 1072 Nightmare
2014-07-24 14:25
274 查看
题目http://acm.hdu.edu.cn/showproblem.php?pid=1072
题目稍长,慢慢看,这题结合栈和队列,基础题
题目稍长,慢慢看,这题结合栈和队列,基础题
#include<stack> #include<queue> #include<cstring> #include<iostream> using namespace std; void que_solve(int m) { queue<int>q; char str[10]; int a; //while(!q.empty()) q.pop(); while(m--) { cin>>str; if(str[0] == 'I') { cin>>a; q.push(a); } else { if(q.empty()) cout<<"None"<<endl; else { cout<<q.front()<<endl; q.pop(); } } } } void sta_solve(int m) { int a; char str[10]; stack<int>s; while(m--) { cin>>str; if(str[0] == 'I') { cin>>a; s.push(a); } else { 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 1072 Nightmare
- hdu1072 Nightmare
- HDU 1072 Nightmare
- hdu 1072 Nightmare(bfs)
- Hdu 1072 - Nightmare
- HDU 1072:Nightmare(BFS)
- HDU 1072 Nightmare
- HDU-1072-nightmare
- Hdu 1072 Nightmare[Bfs]
- hdu1072 Nightmare(bfs)
- Nightmare (HDU 1072)—— BFS
- HDU-1072Nightmare(bfs+可重复访问)
- HDU 1072 Nightmare
- HDU_1072 Nightmare(BFS)
- HDU 1072 Nightmare
- hdu 1072 Nightmare
- HDU 1072 Nightmare
- hdu_1072_Nightmare(BFS)
- hdu1072 Nightmare(bfs)
- hdu 1072 解题报告 ---- Nightmare