Train Problem I

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 31758    Accepted Submission(s): 11976

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
#include <iostream>
#include <stack>
#include <string>
using namespace std;
const int MAXN=;
char o1[MAXN],o2[MAXN];
int n;
string op[MAXN];
int top;
int main()
{
while(cin>>n)
{
cin>>o1>>o2;
top=;
stack<char> st;
for(int i=,j=,len=strlen(o1);i<len;i++)
{
st.push(o1[i]);
op[top++]="in";
while(st.top()==o2[j])
{
st.pop();
j++;
op[top++]="out";
if(st.empty()) break;
}
}
if(st.empty())
{
cout<<"Yes."<<endl;
for(int i=;i<top;i++)
{
cout<<op[i]<<endl;
}
}
else cout<<"No."<<endl;
cout<<"FINISH"<<endl;
} return ;
}

最新文章

  1. 什么是JVM?
  2. ios-高仿别踩白块游戏的实现
  3. jQuery:多个AJAX/JSON请求对应单个回调并行加载
  4. JavaWeb学习记录(二十五)——权限管理总结
  5. UNIX标准化及实现之限制
  6. 将COleDateTime类型数据转换成char *数据
  7. linux中top命令详解
  8. 使用 Jenkins 搭建 iOS/Android 持续集成打包平台【转】
  9. ADPCM编码和解码
  10. 认识ExtJS(04)--常见Web框架的ExtJS改造
  11. Spring Boot分布式系统实践【扩展1】shiro+redis实现session共享、simplesession反序列化失败的问题定位及反思改进
  12. phpstudy 配置端口 和 虚拟域名访问
  13. Mongodb 批量Upsert
  14. 修改和查询sqlserver里面的xml 好像只能一个个改不能批量
  15. A - River Hopscotch
  16. JavaScript基础知识:数据类型,运算符,流程控制,语法,函数。
  17. Idea2018版本建的项目总是找不到主类
  18. sqlserver为数据库表增加自增字段
  19. Ajax请求中的async:false/true
  20. am335x 10.1&quot;电容touch 不能识别

热门文章

  1. S-形函数广泛应用于ANN 的激活函数
  2. vue介绍和简单使用
  3. PAT 1055. 集体照 (25)
  4. LyX中文配置
  5. selenium之坑(StaleElementReferenceException: Message: Element not found in the cache...)
  6. 【leetcode刷题笔记】Longest Common Prefix
  7. 【Flask】Column常用参数
  8. &lt;HTTP协议详解&gt;由浅入深看HTTP
  9. poj 3278 Catch That Cow-搜索进阶-暑假集训
  10. mysql日志总结