#include <iostream>
#include <cstring>
#include <algorithm>
#include <stack>
#include <cstdio>
using namespace std;
const int N=+;
stack <char> ss;
char t1[N];
char t2[N];
int a,b;// a 表示将要入栈的第一个数 b 表示下一个出栈的数
int ans[*N]; int num;
int n;
char str [][]={"in","out"};
int main ()
{
while (~scanf ("%d %s %s",&n,t1+,t2+)) {
while (!ss.empty()) ss.pop();
a=b=; num=;
bool flag=;
while (b<=n) {
if (t1[a]==t2[b]) { ans[++num]=; ans[++num]=; a++; b++; } // 如果入栈的数刚好是出栈的情况
else if (!ss.empty()&&ss.top()==t2[b]) { ans[++num]=; ss.pop(); b++; } //或者直接栈中的第一个数出栈
else if (a<=n) { ans[++num]=; ss.push(t1[a]); a++; }//无法出栈就入栈。。。模拟出栈入栈的顺序
else {
flag=; break;//如果A全部入栈 而无法全部出栈
}
}
if (!flag) cout<<"No." <<endl;
else {
cout<<"Yes."<<endl;
for (int i=;i<=num;i++)
cout<<str[ans[i]]<<endl;
}
cout<<"FINISH"<<endl;
}
return ;
}

hdoj-1022(栈的模拟)的更多相关文章

  1. HDU Train Problem I 1022 栈模拟

    题目大意: 给你一个n 代表有n列 火车,  第一个给你的一个字符串 代表即将进入到轨道上火车的编号顺序, 第二个字符串代表的是 火车出来之后到顺序, 分析一下就知道这,这个问题就是栈, 先进后出吗, ...

  2. HDU1022 Train Problem I 栈的模拟

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1042 栈的模拟,题目大意是已知元素次序, 判断出栈次序是否合理. 需要考虑到各种情况, 分类处理. 常 ...

  3. FZU 1884——排火车——————【栈的模拟】

    排火车 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status P ...

  4. 2018.9.5 Java中使用栈来模拟队列

    栈的规律是是先进后出 队列的规律是先进先出 栈模拟队列 首先我们定义两个栈,一个放数据,一个出数据,判断B栈是否有元素,有元素则直接pop:没有元素则需要我们将A里面的元素出栈然后放到B里面,再取出, ...

  5. HDOJ 1022 模拟栈

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

  6. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  7. hdoj 1022 Train Problem I

    #include<stdio.h> int main() { int n,i,j,k; ],]; ]; while(scanf("%d %s %s",&n,in ...

  8. LeetCode 155 - 最小栈 - [数组模拟栈]

    题目链接:https://leetcode-cn.com/problems/min-stack/description/ 设计一个支持 push,pop,top 操作,并能在常数时间内检索到最小元素的 ...

  9. HDOJ 1022 Train Problem

    两个数组存进出顺序,如果不同进栈,相同出栈.

随机推荐

  1. git找回本地误删的文件

    不小心把本地的文件删除了一个? 想从仓库git pull 下拉? 对不起,这是不行的,虽然不知道为什么,但是我告诉你怎么回复这个文件. 首先,我们先用git status 看看工作区的变化 $ git ...

  2. Centos 7.4 源码 Nginx 安装

    一.安装编译工具及库文件 yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel 二.首先要安装 PCRE ...

  3. 【例子】log4j.properties例子讲解

    log4j.rootLogger=info, ServerDailyRollingFile, stdout log4j.appender.ServerDailyRollingFile=org.apac ...

  4. Win10系列:VC++ Direct3D开发基础1

    在介绍如何使用Direct3D项目模版来绘制立体图形之前,首先为读者介绍在Direct3D应用程序开发过程中涉及到的一些常用概念. (1)资源 资源是指可以被Direct3D图形管线所访问的内存空间, ...

  5. nginx:在linux上进行nginx的安装

    -----1.安装 换源 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 下载: wget ...

  6. pycharm模板

    使用pycharm的模板 File - Settings (ctrl+alt+s) Editor - File and Code Templates - Python Script 可以使用部分变量. ...

  7. 删除Mac OS X中Finder文件打开方式列表的重复程序或失效的

    清理列表, 可以在终端中输入下面提供的一行命令: /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices ...

  8. hybrid几种模式

    native和web适合的场景 Native: 用户体验要求高 业务变动很小(如首页) 性能要求高 Web: 业务变化频繁(如广告) 性能要求低 展示性内容 hybrid App其实会有不同的分支 方 ...

  9. 第二章 使用unittest模块扩展功能测试

    2.1使用功能测试驱动开放一个最简单的应用 # functional_tests.py # -*- coding: utf-8 -*- from selenium import webdriver b ...

  10. StringUtils详细介绍

    StringUtils详细介绍 public static void TestStr(){ #null 和 "" 操作~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ...