HDU-1022-火车进出站问题

简介: HDU-1022-火车进出站问题


<pre name="code" class="plain">


Problem 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      



 


Sample Output

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



Sample Output

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

      题目意思是:      

      有一个车站   3 123  3是有三辆火车进站   123 分别是1 2 3号车   321是车辆开出顺序也就是列车必须是3号车出站后2号车才能出站之后是 1 号,当第 1 号辆进来的时候因为第一辆出战必须是3号车所以此时1号不能走,驶入2号,2号也不能走,驶入3号吗,3号可以走了,接着2号走,然后是1号走。      

      4 1234 2134  此时开出的顺序就不一样了。1号进来不能走,2号进来正好出车顺序是2134 所以 此时2号可以走了,2号走完正好1号走,1 号走完,3号进来,3号接着就出去了,最后是4号进4号出      

      这是在进站的时候就有出站情况的数据      

      /* 4 1234 2134      

Yes.
int
int
out
out
int
out
int
out
FINISH */


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int main()
{
  int n;
  char c[15],g[15],zhan[15];
  int cg[20];
  while(cin>>n>>c>>g)
  {
    memset(cg,0,sizeof(cg));
    int i=-1,j=0,k=-1,x=-1;
    zhan[++k]=c[++i];// 先把第一个进来的车存入栈
    cg[++x]=0;// 进栈用 0 标记(便于一会输出出栈进栈顺序)
    while(c[i]!='\0')
    {
      while(k>=0&&zhan[k]==g[j])//   比如   进栈 123    出栈 321   可以在纸上演示一遍就明白这个循环了
      {
               cg[++x]=1;
               --k;
         ++j;
       }
                 cg[++x]=0;
           zhan[++k]=c[++i];
    }
    if(i==n&&j==n)
    {
      printf("Yes.\n");
      for(i=0;i<x;i++)
         puts(cg[i]?"out":"in");
    }
    else  puts("No.");
      puts("FINISH");
  }
  return 0;
}
</pre></div>


目录
相关文章
|
存储 运维 Dubbo
SAE急速部署
Serverless应用引擎 2.0的推出,您是否用过?更快速的部署,更低的成本,SAE 2.0 极简体验、极致弹性,助力企业降本增效!
10162 14
SAE急速部署
|
存储 搜索推荐 算法
“插入排序:小数据量排序的王者“
“插入排序:小数据量排序的王者“
289 0
|
算法 C++
算法基础系列第五章——动态规划之背包问题(2)
算法基础系列第五章——动态规划之背包问题(2)
103 0
算法基础系列第五章——动态规划之背包问题(2)
|
设计模式 消息中间件 JavaScript
图解设计模式之发布-订阅模式(TypeScript)上
图解设计模式之发布-订阅模式(TypeScript)上
551 0
|
前端开发 开发者
CSS怪异盒子 | 学习笔记
快速学习CSS怪异盒子
|
Java 数据库连接 数据库
SpringBoot整合Mybatis
SpringBoot整合Mybatis
|
2天前
|
人工智能 运维 安全
|
4天前
|
SpringCloudAlibaba 负载均衡 Dubbo
微服务架构下Feign和Dubbo的性能大比拼,到底鹿死谁手?
本文对比分析了SpringCloudAlibaba框架下Feign与Dubbo的服务调用性能及差异。Feign基于HTTP协议,使用简单,适合轻量级微服务架构;Dubbo采用RPC通信,性能更优,支持丰富的服务治理功能。通过实际测试,Dubbo在调用性能、负载均衡和服务发现方面表现更出色。两者各有适用场景,可根据项目需求灵活选择。
384 124
微服务架构下Feign和Dubbo的性能大比拼,到底鹿死谁手?
|
7天前
|
人工智能 JavaScript 测试技术
Qwen3-Coder入门教程|10分钟搞定安装配置
Qwen3-Coder 挑战赛简介:无论你是编程小白还是办公达人,都能通过本教程快速上手 Qwen-Code CLI,利用 AI 轻松实现代码编写、文档处理等任务。内容涵盖 API 配置、CLI 安装及多种实用案例,助你提升效率,体验智能编码的乐趣。
682 107