#include<iostream>
#include<vector>
#include<cstring>
#include<string>
#include<stack>
#include<map>
using namespace std;

];
/*
    栈的应用
    若in[i]==out[j]则先进栈后立即出栈,此时只需i++,j++;
    若in[i]!=out[j]检查栈首是否为out[j],若是,则出栈,并j++,否则将in[i]入栈,并j++
    i==n时,若栈不为空则说明任有火车未出栈,检查栈内元素==out[j++]   f[i]: 1表示进栈,0表示出栈
    。。。。期末考试时不会做,遂记之
*/
int main()
{
    freopen("d:\\in.txt", "r", stdin);
    freopen("d:\\out.txt", "w", stdout);
    string in, out;
    int n;
    while(cin>>n)
    {
        ;
        cin>>in>>out;
        bool flag=true;
        , j=;
        stack<char>s;
        while(i<n) {
            if(in[i]==out[j]){
                i++; j++;
                f[cur++]=;
                f[cur++]=;
            }else if(!s.empty()){
                char first=s.top();
                if(first==out[j]){
                    j++;
                    s.pop();
                    f[cur++]=;
                }else{
                    s.push(in[i++]);
                    f[cur++]=;
                }
            }else {
                s.push(in[i++]);
                f[cur++]=;
            }
        }
        while(!s.empty()){
            char first=s.top();
            f[cur++]=;
            s.pop();
            if(first != out[j++]){
                flag=false;
                break;
            }
        }
        if(flag){
            cout<<"Yes."<<endl;
            ; i<cur; i++){
                )cout<<"in"<<endl;
                else cout<<"out"<<endl;
            }
            cout<<"FINISH"<<endl;
        } else {
            cout<<"No.\nFINISH"<<endl;
        }
    }
    ;
}

hdu 1022 Train Problem I(栈)的更多相关文章

  1. Hdu 1022 Train Problem I 栈

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

  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. hdu 1022 Train Problem I【模拟出入栈】

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

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

  5. HDU - 1022 Train Problem I STL 压栈

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

  6. hdu 1022 Train Problem I(栈的应用+STL)

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

  7. hdu 1022:Train Problem I(数据结构,栈,递归,dfs)

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

  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

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

  10. hdu 1022 Train Problem

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

随机推荐

  1. 负载均衡,最理想使用 redis实现session共享

    负载均衡在多台php服务器负载均衡的情况下,第一秒请求是a服务器,第二秒请求是b服务器, session必须放在一个公共的服务器,最理想是使用 redis实现session共享.内存的速度比磁盘访问快 ...

  2. EXCEL 数字统一转换成文本

    将excel中的数字统一转换成文本形式.即添加‘. 1.点击数据-分列. 2.分隔符号-下一步. 3.选择文本识别符号,如“‘”分号. 4. 选中文本-完成.

  3. spark yarn任务的executor 无故 timeout之原因分析

    问题: 用  spark-submit --master yarn --deploy-mode cluster --driver-memory 2G --num-executors 6 --execu ...

  4. [6278009]使用Visual Stuido Code 编写Markdown

    使用Visual Stuido Code 编写Markdown void main() { printf("Hello world!"); } void main() { Cons ...

  5. Angular-ui-router + oclazyload + requirejs实现资源随route懒加载

    刚开始用angularjs做项目的时候,我用的是ng-router,觉得加载并不好.所以就用了ui-router,考虑到在app上网页加载速度太慢,所以我就想到了用懒加载,看下是否能提升性能,提高加载 ...

  6. Apache Storm简介

    Apache Storm简介 Storm是一个分布式的,可靠的,容错的数据流处理系统.Storm集群的输入流由一个被称作spout的组件管理,spout把数据传递给bolt, bolt要么把数据保存到 ...

  7. Tiny6410之LED裸机驱动

    操作步骤: 第一步:查看开发板电路原理图 找到LED 的管脚所对应的寄存器 nLED_1 - GPK4 nLED_2 - GPK5 nLED_3 - GPK6 nLED_4 - GPK7 由原理图可知 ...

  8. centos 日常操作指令

    ls  ls -li 查看当前目录下所有目录 ls -al 查看当前目录下所有目录包括隐藏文件 CD  cd 目录 跳转指定目录 cd ..返回上级目录 cd / 返回根目录 VI  1. 使用vi进 ...

  9. WinForm 布局,容器、打印和对话框控件

    今天,我主要学习了容器控件.打印控件.对话框控件. 在正式进行今天的内容之前,首先补充了布局的两个属性:Anchor:锁定位置,Dock:填充位置,一般与容器控件配合使用. 之后,我学习了第一部分内容 ...

  10. 解决Mac Linux USB Loader“Couldn't get security scoped bookmarks”错误

    Mac Linux USB Loader出现 "Couldn't get security scoped bookmarks"错误时, 需要删除 ~/Library/Contain ...