A - Train Problem I

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Description

As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ignatius Train Station is the fastest all over the world ^v^). But here comes a problem, there is only one railway where all the trains stop. So all the trains come in from one side and get out from the other side. For this problem, if train A gets into the railway first, and then train B gets into the railway before train A leaves, train A can't leave until train B leaves. The pictures below figure out the problem. Now the problem for you is, there are at most 9 trains in the station, all the trains has an ID(numbered from 1 to n), the trains get into the railway in an order O1, your task is to determine whether the trains can get out in an order O2. 
 

Input

The input contains several test cases. Each test case consists of an integer, the number of trains, and two strings, the order of the trains come in:O1, and the order of the trains leave:O2. The input is terminated by the end of file. More details in the Sample Input. 
 

Output

The output contains a string "No." if you can't exchange O2 to O1, or you should output a line contains "Yes.", and then output your way in exchanging the order(you should output "in" for a train getting into the railway, and "out" for a train getting out of the railway). Print a line contains "FINISH" after each test case. More details in the Sample Output. 
 

Sample Input

3 123 321
3 123 312
 

Sample Output

Yes.
in
in
in
out
out
out
FINISH
No.
FINISH

Hint

Hint  For the first Sample Input, we let train 1 get in, then train 2 and train 3.
So now train 3 is at the top of the railway, so train 3 can leave first, then train 2 and train 1.
In the second Sample input, we should let train 3 leave first, so we have to let train 1 get in, then train 2 and train 3.
Now we can let train 3 leave.
But after that we can't let train 1 leave before train 2, because train 2 is at the top of the railway at the moment.
So we output "No.". 题意大体是 询问出栈入栈是否符合栈的规定,如果符合 输入顺序;否则no。最后finsh 代码
 #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<iostream>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,i,j,k,flag[];
char s1[],s2[];
int main()
{
stack <char> s;
while(~scanf("%d",&n)){
memset(flag,-,sizeof(flag));
cin>>s1>>s2;
while(!s.empty()) s.pop();
j=,k=;
for(int i=;i<n;i++){
s.push(s1[i]);
flag[k++]=;
while(!s.empty()&&s.top()==s2[j])
flag[k++]=,s.pop(),j++;
}
if(j==n){
printf("Yes.\n");
for(int i=;i<k;i++)
if(flag[i]) printf("in\n");
else printf("out\n");
printf("FINISH\n");
}else{
printf("No.\n");
printf("FINISH\n");
}
}
return ;
}

HDU 1022 Train Problem I的更多相关文章

  1. HDU 1022 Train Problem I(栈的操作规则)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1022 Train Problem I Time Limit: 2000/1000 MS (Java/Ot ...

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

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

  3. Hdu 1022 Train Problem I 栈

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

  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

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

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

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

随机推荐

  1. C语言笔记

    .c是C语言源文件,在编写代码的时候创建 .o是目标文件,在编译成功的时候产生  .obj .out是可执行文件,在链接成功的时候产生 工具:clang编译器(Xcode3 gcc Xcode4 LL ...

  2. NSURLConnection获取一个MP3文件

    NSURLConnection网络请求 直接上代码-这个没什么说的,你们自己有兴趣可以自己试试 代码 #import "ViewController.h" @interface V ...

  3. 配置Kotlin环境(DataBinding)

    1.安装Kotlin插件 在plugin中搜索kotlin,安装两个kotlin插件,重新启动Android Studio.2.build.gradle(project level) buildscr ...

  4. get和post的区别与乱码问题解决

    ★ get和post的区别:     1.get请求通过url地址发送请求参数,可以在地址栏上直接显示     2.post请求通过请求体发送请求参数,不会再地址栏上显示     3.get在地址栏显 ...

  5. IT行业常见职位职业路线图

    我曾经面试过一些计算机相关毕业的应届生,问他希望做什么工作时,他回答只要是软件开发就好了,再细问一下你了解到的软件开发是怎样的?除了软件开发,还有其它什么工作?就答不出来了. 这里我先给出一张IT知识 ...

  6. 创建用户故事地图(User Story Mapping)的8个步骤

    [小编]上周六了解了用户故事地图后,小编又查阅了一些资料,找到了以下这篇关于如何组织用户故事地图规划的文章,分享给大家.也希望大家如果有好的实践,也可以留言一起交流. 原文地址:http://winn ...

  7. react学习笔记1

    # 1.hello world 学习一个语言,最好的方式,我们需要去官网去查看文档(https://facebook.github.io/react),通过JSFiddle,便可以看到最简单的demo ...

  8. SQL Server中的RAND函数的介绍和区间随机数值函数的实现

        工作中会遇到SQL Server模拟数据生成以及数值列值(如整型.日期和时间数据类型)随机填充等等任务,这些任务中都要使用到随机数.鉴于此,本文将对SQL Server中随机数的使用简单做个总 ...

  9. C语言 时间函数的学习和总结

    一直都是以简单的time_t t,time(&t),ctime(&t)来表示时间,后来要以时间为日志文件的名字时,就有点蒙逼了.学习一下.   tm结构: struct tm {   ...

  10. Redis-benchmark测试Redis性能

    Redis-benchmark是官方自带的Redis性能测试工具,可以有效的测试Redis服务的性能. 使用说明如下: Usage: redis-benchmark [-h <host>] ...