hdu 1702 ACboy needs your help again!
来源:互联网 发布:吉尼佛摄影吧淘宝 编辑:程序博客网 时间:2024/06/03 21:31
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1702
题目大意:按照所给要求,输出相应的数。“FIFO”指代先进先出,即队列的概念,“FILO”指代先进后出,即栈的表现形式~这里定义两个函数即可,一个队列,一个栈的调用!
1 #include <iostream> 2 #include <cstdio> 3 #include <queue> 4 #include <stack> 5 #include <cstring> 6 using namespace std; 7 8 int s,p,o,z,q; 9 char ch[105],str[105];10 11 int FIFO(int w)12 {13 queue<int>q,qq;14 for (int i=0; i<w; i++)15 {16 scanf("%s",ch);17 if (strcmp(ch,"IN")==0)18 {19 scanf("%d",&o);20 q.push(o);21 }22 else if (strcmp(ch,"OUT")==0)23 {24 if (!q.empty())25 {26 s=q.front();27 cout<<s<<endl;28 q.pop();29 }30 else31 cout<<"None"<<endl;32 33 }34 }35 }36 int FILO(int w)37 {38 stack<int>q,qq;39 for (int i=0; i<w; i++)40 {41 scanf("%s",ch);42 if (strcmp(ch,"IN")==0)43 {44 scanf("%d",&p);45 q.push(p);46 }47 else if (strcmp(ch,"OUT")==0)48 {49 if (!q.empty())50 {51 z=q.top();52 cout<<z<<endl;53 q.pop();54 }55 else56 cout<<"None"<<endl;57 }58 }59 }60 int main ()61 {62 int n,m;63 while (cin>>n)64 {65 while (n--)66 {67 scanf ("%d%s",&m,str);68 //scanf("%s %d",ch,m);69 if (strcmp(str,"FIFO")==0)70 FIFO(m);71 else72 FILO(m);73 }74 }75 return 0;76 }
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!
- 【UI布局优化】Android布局优化的几种方式
- android:hint 默认提示内容
- hdu 1509 Windows Message Queue (优先队列)
- hdu 1870 愚人节的礼物
- hdu 1873 看病要排队
- hdu 1702 ACboy needs your help again!
- system V信号量和Posix信号量
- websphere8 从安装到部署 测试集群应用程序 安装j2ee程序(非常详细)
- hdu 1518 Square(深搜+剪枝)
- hdu 1195 Open the Lock
- poj 1363 Rails
- Android碎片第五期
- hdu 1237 简单计算器
- hdu 1061 Rightmost Digit