题意:给我们两个序列,看能否通过压栈,出栈将第一个序列转换成第二个。

思路:将序列 1 依次压栈,同时看是否和序列 2 当前元素相同

代码如下:

#include<iostream>
#include<stack>
#define max 100
using namespace std;
int main()
{
stack<char>s;
int n,i,j,k,result[max];
char str1[max],str2[max];
while(cin>>n>>str1>>str2)
{
i=;
j=;
k=;
s.push(str1[]); //防止栈空,压一个进去
result[] = ; //记录进来了一个
while(i < n && j < n)
{
if(s.size() && s.top() == str2[j]) //若栈顶元素与序列 2 当前元素相同
{
s.pop(); //出栈
result[k ++] = ;
j ++;
}
else
{
if(i == n) break;
s.push(str1[++ i]);
result[k ++] =;
}
}
if(i == n) //表示栈顶元素不等于序列 2 当前元素,且序列 1 中的元素全部入过栈
{
cout<<"No.\n";
}
else
{
cout<<"Yes.\n";
for(i = ; i < k; i++)
if(result[i])
cout<<"in\n";
else
cout<<"out\n";
}
cout<<"FINISH\n";
}
return ;
}

H 1022 Train Problem Ⅰ的更多相关文章

  1. sicily 1022. Train Problem

    本题主要是出栈入栈顺序的问题 Home Problems My Status Standing <->           1022. Train Problem     Total: 2 ...

  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 ...

  3. Problem : 1022 ( Train Problem I )

    做题思路必须很清晰啊....可以用数组存储in或out来着,第一次C++用string啊,效果还行 Problem : 1022 ( Train Problem I ) Judge Status : ...

  4. HDU 1022 Train Problem I

    A - Train Problem I Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

  5. hdu 1022 Train Problem I【模拟出入栈】

    Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  6. Hdu 1022 Train Problem I 栈

    Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. HDU - 1022 Train Problem I STL 压栈

    Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. HDU 1022 Train Problem I[给出两个长n的串,入栈和出栈顺序,判断入栈顺序是否可以匹配出栈顺序]

    Train Problem I 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描述 As the new term comes, the Ignatius Train Sta ...

  9. HDU 1022.Train Problem I【栈的应用】【8月19】

    Train Problem I Problem Description As the new term comes, the Ignatius Train Station is very busy n ...

随机推荐

  1. 直接用<img> 的src属性显示base64转码后的字符串成图片

    直接用<img> 的src属性显示base64转码后的字符串成图片 <img src="base64转码后的字符串" ></img> 下面的图片 ...

  2. 简单的html和css

    整体图太大了,看不太清楚,下面是分开的图 第一张: 第二张:

  3. B. Shaass and Bookshelf DP

    http://codeforces.com/contest/294/problem/B 据说是贪心,我用了一个复杂度是2e8的dp水过去了. 其实这题就是给你n个数,每个数有两个权值,分成两组,使得第 ...

  4. Unity开发心路历程——制作画板

    有人说 编程是份很无聊的工作 因为整个工作时间面对的都是电脑这种机器 因为眼睛盯着的内容都是索然无味的代码 因为总是会有意想不到的bug让你怀疑自己的智商 而我认为 编程是件及其有意思的事情 可观的收 ...

  5. ios UILabel在storyBoard或xib中如何在每行文字不显示完就换行

    大家知道怎么用代码让label中的文字换行,只需要 label.numberOfLines = 0; label.text = @"这是第一行啦啦啦啦,\n这是第二行啦啦,\n这是第三行&q ...

  6. iOS 自定义图片和文字垂直显示按钮<上面是图片,文字显示下面>

    #import <UIKit/UIKit.h> @interface VerticalButton : UIButton @end #import "VerticalButton ...

  7. js常用方法

    若未声明,则都是js的方法 1.indexOf indexOf(str):默认返回字符串中第一次出现索引位置 的下标,没有则返回-1 indexOf(str,position):返回从position ...

  8. 非阻塞同步算法实战(二)-BoundlessCyclicBarrier

    本人是本文的作者,首发于ifeve(非阻塞同步算法实战(二)-BoundlessCyclicBarrier) 前言 相比上一 篇而言,本文不需要太多的准备知识,但技巧性更强一些.因为分析.设计的过程比 ...

  9. docke部署mysql

    #1    docker pull mysql #2    docker run -v /data/var/mysql/:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=k ...

  10. XE3随笔21:系统默认语言与系统支持的语言列表

    unit Unit1; interface uses   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, For ...