您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: