hdu 1022
// hdu1022
这题算是我做的第一道栈的题目,之前看过栈的一些内容,做这道题的时候,可以模拟出过程,但是具体的代码不会写。。。所以决定练习一些栈和队列的问题,大概思路就是有三个数组和一个栈,先把第一个数组的第一个元素放进栈里,每次判断第二个数组和栈顶元素是否相等,如果相等就弹出,如果不相等就压入,大概就是这个思路。。。。
#include <iostream>
#include <stack>
using namespace std;
int main()
{
stack<char>s;
int n;
char a[100],b[100];
while(cin>>n>>a>>b)
{
int i=1,j=0,flag[100],k=1;
s.push(a[0]);
flag[0]=0;
while(i<n+1&&j<n)
{
if(s.size()!=0&&s.top()==b[j])
{
j++;
s.pop();
flag[k++]=1;
}
else
{
if(i==n+1) break;
s.push(a[i++]);
flag[k++]=0;
}
//cout<<i<<endl;
}
//cout<<i<<" "<<j<<endl;
if(i==n+1)
cout<<"No.\n";
else
{cout<<"Yes.\n";
for(i=0;i<k;i++)
if(flag[i]==1)
cout<<"out\n";
else
cout<<"in\n";}
cout<<"FINISH\n";
}
return 0;
}
hdu 1022的更多相关文章
- HDU 1022 Train Problem I
A - Train Problem I Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- Train Problem I hdu 1022(栈)
http://acm.split.hdu.edu.cn/showproblem.php?pid=1022 题意:给出火车的进站与出站顺序,判断是否可以按照给出的出站顺序出站. #include < ...
- hdu 1022 Train Problem I 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1022 又是一道栈的练习,这次也是没有用到STL中的栈来实现.用来保存操作过程的数组(process[] ...
- HDU 1022 火车进站【栈】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1022 题目大意: 题目大概意思:有N辆火车,以序列1方式进站,判断是否能以序列2方式出栈.进站不一定 ...
- HDU 1022 Train Problem I(栈的操作规则)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1022 Train Problem I Time Limit: 2000/1000 MS (Java/Ot ...
- hdu 1022 Train Problem I【模拟出入栈】
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- HDU 1022 Train Problem I(栈模拟)
传送门 Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of st ...
- 栈的简单应用 HDU 1022 http://acm.hdu.edu.cn/showproblem.php?pid=1022
#include<stdio.h> #include<stack> #include<string.h> #define N 20 using namespace ...
- HDOJ/HDU 1022 Train Problem I(模拟栈)
Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot o ...
随机推荐
- bash shell学习-shell基础 (笔记)
When you hoist the sails to cross the sea, you willride the wind and cleave the waves. "长风破浪会有时 ...
- call和apply
在js中经常会看到call和apply,他们实际上就是用于改变this的上下文 经典例子 function pet(words) { this.words=words; this.speak=func ...
- JS笔记1
1.每个函数对象都有一个length属性,表示该函数期望接收的参数个数.它与函数的arguments不同,arguments.length表示函数实际接收的参数个数. 2.javascript 中有五 ...
- 延迟加载并渐现内容的jquery插件lazyFade
http://www.jqcool.net/demo/201412/jquery-lazyfade/
- php网站判断用户是否是手机访问的方法
PHP网站判断用户是否用手机访问,如果是手机的话,就跳转到指定的手机友好页面.随着移动设备的普及,网站也会迎来越来越多移动设备的访问.用适应PC的页面,很多时候对手机用户不友好,那么有些时候,我们需要 ...
- django + nginx + raspberypi + pidaro
对于一个从事后台开发的人来说,搞了个网站,我自己都觉得有点意外.不是很懂html,不是很懂css,不是很懂js,不是很懂web开发模式/框架,不是很懂httpd/nginx--,web的东西样 ...
- ExtJS5_自定义菜单1
顶部和底部区域已经作好,在顶部区域有一个菜单的按钮,这一节我们设计一个菜单的数据结构,使其可以展示出不同样式的菜单.由于准备搭建的是一个系统模块自定义的系统,因此菜单也是自定义的,在操作员系统登录的时 ...
- 利用ordered hints优化SQL
SQL_ID 4g70n3k9bqc5v, child number 0 ------------------------------------- MERGE INTO YJBZH_GRXDFHZ ...
- 【HDOJ】3400 Line belt
三分. #include <cstdio> #include <cstring> #include <cmath> typedef struct { double ...
- (转载)PHP mb_substr函数在实际编码中的应用方法
(转载)http://developer.51cto.com/art/200912/166080.htm 我们在使用PHP语言进行实际编码中时,通常会遇到许多错误的出现,比如在截取字符串时会出现乱码等 ...