HDU 1022 Train Problem I 栈、队列
来源:互联网 发布:能写作的软件 编辑:程序博客网 时间:2024/06/08 13:18
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1022
货车进出站,相当于STL里面的栈stack,知道了这一点,就很简单了。
stack函数:
1、push():进栈。
2、pop():出栈。
3、empty():栈是否为空。
4、top():栈顶。
代码如下:
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include <algorithm>#include <vector>#include <set>#include <map>#include <queue>#include <stack>using namespace std;/*freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);*/char a[10],b[10];char ans[100];int main(){ int i,j,n; while(cin>>n) {//以b形式进站,以a形式出站 for(i=1;i<=n;i++) cin>>b[i]; for(i=1;i<=n;i++) cin>>a[i]; int A=1,B=1,t=0,flag=0; stack<int>q; while(A<=n) { if(a[A]==b[B]&&B<=n)//B<=n一定要加,因为上一组可能对这一组有影响 {//a与b相等,进去后马上出栈 A++;B++; ans[t++]='i'; ans[t++]='o'; } else if(!q.empty()&&q.top()==a[A]) {//栈顶与a相等,出栈 A++; q.pop(); ans[t++]='o'; } else if(B<n) {//b进栈 q.push(b[B]); B++; ans[t++]='i'; } else {//不可能,标记break flag=1; break; } } if(flag==0) { printf("Yes.\n"); for(i=0;i<t;i++) { if(ans[i]=='i') printf("in\n"); else printf("out\n"); } } else printf("No.\n"); printf("FINISH\n"); } return 520;}
- HDU 1022 Train Problem I 栈、队列
- HDU 1022 Train Problem I 栈和队列
- hdu 1022 Train Problem I 栈
- Train Problem I hdu 1022 栈
- hdu 1022 Train Problem I(栈)
- hdu 1022 Train problem I(栈~~)
- hdu 1022 Train Problem I(栈)
- HDU 1022 Train Problem I (栈)
- HDU 1022 Train Problem I 栈
- hdu 1022 Train Problem I(栈)
- hdu 1022 Train Problem I 栈模拟
- HDU 1022 Train Problem I【栈】
- hdu 1022----Train Problem I(栈)
- hdu 1022 Train Problem I (栈)
- HDU 1022 Train Problem I 【栈】
- HDU - 1022 - Train Problem I(栈)
- HDU 1022 Train Problem I(栈)
- HDU 1022 Train Problem I 栈
- 试题集
- ARC指南2 - ARC的开启和禁止
- anova
- c/c++开发工具
- 两个C++编译错误及解决办法--does not name a type和field `XX' has incomplete type
- HDU 1022 Train Problem I 栈、队列
- 单链表的初始化,建立,插入,查找,删除。
- 双链表的初始化,建立,插入,查找,删除
- 单元测试的意义
- 循环单链表的初始化,建立,插入,查找,删除
- mongodb意外退出无法启动解决办法(Unclean shutdown detected.)
- 关于解决android图片设置时outofmemery的问题!!!!!!!!!!
- 浅谈Struts2拦截器的原理与实现
- mer类