HDU 1702 ACboy needs your help again!(栈和队列)
2015-10-02 12:51
447 查看
题目地址:点击打开链接
题意:简单栈和队列的模拟
思路:水题
AC代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <climits>
#include <cmath>
#include <cctype>
using namespace std;
char a[10];
int main()
{
int t,n,i,x,y;
scanf("%d",&t);
while(t--)
{
scanf("%d%s",&n,a);
if(strcmp(a,"FIFO") == 0)
{
queue<int> q;
for(i=0; i<n; i++)
{
scanf("%s",a);
if(strcmp(a,"IN") == 0)
{
scanf("%d",&x);
q.push(x);
}
else
{
if(q.empty())
printf("None\n");
else
{
y = q.front();
q.pop();
printf("%d\n",y);
}
}
}
}
else
{
stack<int> s;
for(i=0; i<n; i++)
{
scanf("%s",a);
if(strcmp(a,"IN") == 0)
{
scanf("%d",&x);
s.push(x);
}
else
{
if(s.empty())
printf("None\n");
else
{
y = s.top();
s.pop();
printf("%d\n",y);
}
}
}
}
}
return 0;
}
题意:简单栈和队列的模拟
思路:水题
AC代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <climits>
#include <cmath>
#include <cctype>
using namespace std;
char a[10];
int main()
{
int t,n,i,x,y;
scanf("%d",&t);
while(t--)
{
scanf("%d%s",&n,a);
if(strcmp(a,"FIFO") == 0)
{
queue<int> q;
for(i=0; i<n; i++)
{
scanf("%s",a);
if(strcmp(a,"IN") == 0)
{
scanf("%d",&x);
q.push(x);
}
else
{
if(q.empty())
printf("None\n");
else
{
y = q.front();
q.pop();
printf("%d\n",y);
}
}
}
}
else
{
stack<int> s;
for(i=0; i<n; i++)
{
scanf("%s",a);
if(strcmp(a,"IN") == 0)
{
scanf("%d",&x);
s.push(x);
}
else
{
if(s.empty())
printf("None\n");
else
{
y = s.top();
s.pop();
printf("%d\n",y);
}
}
}
}
}
return 0;
}
相关文章推荐
- poj 1995 Raising Modulo Numbers【快速幂】
- 解决:CWnd::SetWindowText报Assertion failure
- AIDL调用第三方应用程序服务中的方法
- wait函数返回值总结http://blog.csdn.net/astrotycoon/article/details/41172389
- system函数的总结 http://blog.csdn.net/astrotycoon/article/details/40626355
- 【MongoDB】2014-07-25T11:00:48.634+0800 warning: Failed to connect to 127.0.0.1:27017, reason: errno:1
- linux避免僵死进程方法总结 http://blog.csdn.net/astrotycoon/article/details/39717143
- waitpid(or wait)和SIGCHILD的关系 http://blog.csdn.net/liuxingen/article/details/38350347
- Linux的system()和popen()差异 http://blog.csdn.net/liuxingen/article/details/47057539
- Sails的简单学习
- Treat your machine fair
- Learning Spark - LIGHTNING-FAST DATA ANALYSIS 第四章 - (4)
- Aizu 2304 Reverse Roads
- Aizu 2300 Calender Colors dfs
- 2015 Autumn Training #0
- Aizu 2306 Rabbit Party DFS
- Aizu 2305 Beautiful Currency DP
- Aizu 2304 Reverse Roads 费用流
- Aizu 2302 On or Off dfs/贪心
- hdu 4300 Clairewd’s message (kmp)