HDU 1072 ACboy needs your help again!(栈和队列)
来源:互联网 发布:setscale java 编辑:程序博客网 时间:2024/04/28 07:48
ACboy needs your help again!
题目来源:点击打开链接
题目分析:这道题就是一个栈和队列的简单应用;栈:先进后出" FILO ",队列:先进先出" FIFO ".
c 源代码:
#include<stdio.h>#include<stack>#include<queue>using namespace std;int main(){stack<int>s;queue<int>q;int t,n,a;char str[5],str1[5]; //利用数组存储scanf("%d",&t);while(t--){scanf("%d",&n);scanf("%s",str);while(!q.empty())//注意,要将栈和队列先制空 q.pop(); while(!s.empty()) s.pop();while(n--){scanf("%s",str1);if(str1[0]=='I'&&str[2]=='F') // 单个字符{scanf("%d",&a);q.push(a);}if(str1[0]=='I'&&str[2]=='L'){scanf("%d",&a);s.push(a);}if(str1[0]=='O'&&str[2]=='F'){if(!q.empty()){printf("%d\n",q.front());q.pop();}elseprintf("None\n");}if(str1[0]=='O'&&str[2]=='L'){if(!s.empty()){printf("%d\n",s.top());s.pop();}elseprintf("None\n");}}}return 0;}
c++ 源代码:
#include <iostream>#include<stdio.h>#include <string>#include <queue>#include <stack>using namespace std;int main(){ stack<int> s; queue<int> q; string str, str1; //c++ 里面直接定义字符串 int t,n,a; scanf("%d",&t); while(t--) { scanf("%d",&n); cin>>str; while(!q.empty()) q.pop(); while(!s.empty()) s.pop(); while(n--) { cin>>str1; if((str1=="IN")&&(str=="FIFO")) //直接比较字符串 { scanf("%d",&a); q.push(a); } if((str1=="IN")&&(str=="FILO")) { scanf("%d",&a); s.push(a); } if((str1=="OUT")&&(str=="FIFO")) { if(!q.empty()) { printf("%d\n",q.front()); q.pop(); } else printf("None\n"); } if((str1=="OUT")&&(str=="FILO")) { if(!s.empty()) { printf("%d\n",s.top()); s.pop(); } else printf("None\n"); } } } return 0;}
两者大同小异,就是注意一下字符串!!
0 0
- HDU 1072 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!(栈&&队列)
- HDU-1702 ACboy needs your help again!【栈与队列】
- hdu1702 ACboy needs your help again!(栈和队列
- ACboy needs your help again!(栈和队列)
- ACboy needs your help again! 队列和栈的应用
- HDU1702--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!(栈和队列的结合)
- Mac 10.10 安装nginx
- android开发规范
- Linked List Cycle I,II, Partition List
- 藤田麻衣子 覚悟を決めて。
- 整除一个整数的方法
- HDU 1072 ACboy needs your help again!(栈和队列)
- 有关Entity Framework的数据模型的操作(二)业务层
- Emacs安装R开发环境ESS
- 031 二进制中1的个数(keep it up, 看到这个题刚开始有点蒙)
- 小知识点.字符串
- git config命令使用第一篇——介绍,基本操作,增删改查
- 映射map
- hdu 2874 Tarjan离线 LCA
- git config命令使用第二篇——section操作,多个key值操作,使用正则