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 ...
随机推荐
- 仿猪八戒一个提示(jQuery插件) v0.1 beta
先看下效果 js jQuery.extend({ prompt: function (text, type, times) { var prompt = $(['<div class=" ...
- Delphi-Delete 过程
过程名称 Delete 所在单元 System 过程原型 procedure Delete ( var Source : string; StartChar : Integer; Count : In ...
- 关于System.out.println()与System.out.print("\n")的区别
这是在写junit测试的时候发现的. import java.io.ByteArrayOutputStream; import java.io.PrintStream; public class Te ...
- windows10 预览版 中英文官方下载地址+激活密钥+网盘分享
windows10 预览版 中英文官方下载地址+激活密钥+网盘分享 产品密钥:NKJFK-GPHP7-G8C3J-P6JXR-HQRJR 英语 64 位 (x64) http://iso.esd.m ...
- Fireworks Extension —— AutoSlice 介绍
前不久在网上到处瞎晃的时候,发现Adobe的软件几乎都可以写插件.Fireworks更是很早的版本就支持使用javascript编写插件,于是乎如入桃园,奋斗几日为VD小伙伴们写了一个插件,命名Aut ...
- linq 的Distinct 扩展方法.
List<miniclass> classs = new List<miniclass>(); classs.Add(new miniclass() { token = &qu ...
- Java中start和run方法的区别
一.问题引入 说到这两个方法就不得不说多线程,说到多线程就不得不提实现多线程的两种方式继承Thread类和实现Runable接口,下面先看这两种方式的区别. 二. Java中实现多线程 ...
- 启动weblogic11g一直提示<141281> <unable to get file lock, will retry ...>
一次非正常关闭weblogic之后,再次启动时启动不成功,一直提示:<141281> <unable to get file lock, will retry ...> 解决方 ...
- CENTOS纯手工安装LAMP+PHPMYADMIN
现在,安装这些确实越来越方便了. Installing Apache2 With PHP5 And MySQL Support On CentOS 6.4 (LAMP) 参考URL: http://w ...
- 用UltraEdit折叠宏定义
在UltraEdit中通过“高级->配置->导航->编辑器显示->语法高亮->文档的完整目录名称”取得“c_cplusplus.uew”文件存放的目录. 在“c_cplu ...