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

思路:将序列 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. [字符编码]Invalid byte 1 of 1-byte UTF-8 sequence终极解决方案

    今天在eclipse中编写pom.xml文件时,注释中的中文被eclipse识别到错误:Invalid byte 1 of 1-byte UTF-8 sequence,曾多次遇到该问题,问题的根源是: ...

  2. Java对象的序列化和反序列化

    对象的序列化是指将对象转换为字节序列的过程 对象的反序列化是指将字节序列恢复对象的过程 主要有两种用途: 1.把对象的字节序列永久地保存在硬盘上,通常放在一个文件中. 2.在网络上传输对象的字节序列. ...

  3. LeetCode OJ 112. Path Sum

    Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all ...

  4. python中的告警处理

    在Python中,遇到异常时,一类是直接抛出异常,exception:另一类直接告警warning. 对于后者,通常是打印一句话.前者则或中断程序执行. 考虑到避免由于告警导致后续的不可预知的错误,可 ...

  5. SQL中CONVERT日期不同格式的转换用法

    SQL中CONVERT日期不同格式的转换用法 格式: CONVERT(data_type,expression[,style]) 说明:此样式一般在时间类型(datetime,smalldatetim ...

  6. 一些简单的PGSQL 操作

    1.jsonb字段的查询 enterprisearr 字段类型为jsonb,存储格式为["物流服务商","销售服务商","供应商"]. SE ...

  7. jQuery 的属性

    一.显示和隐藏的属性  hide(隐藏),show(显示) 下面是例子 <script type="text/javascript"> $(document).read ...

  8. 【转】+【举例】ArcGIS中的坐标系统定义与投影转换

    背景知识: UTM (Universal Transverse Mercator)坐标系是由美国军方在1947提出的.虽然我们仍然将其看作与"高斯-克吕格"相似的坐标系统,但实际上 ...

  9. jQuery Mobile 列表视图(带有自动检索)

    输入a: 输入b: jQuery Mobile 列表视图 jQuery Mobile 中的列表视图是标准的 HTML 列表:有序列表 (<ol>) 和无序列表 (<ul>). ...

  10. Computer Vision 学习 -- 图像存储格式

    本文把自己理解的图像存储格式总结一下. 计算机中的数据,都是二进制的,所以图片也不例外. 这是opencv文档的描述,具体在代码里面,使用矩阵来进行存储. 类似下图是(BGR格式): 图片的最小单位是 ...