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

  1. Hint For the first Sample Input, we let train 1 get in, then train 2 and train 3.
  2. So now train 3 is at the top of the railway, so train 3 can leave first, then train 2 and train 1.
  3. 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.
  4. Now we can let train 3 leave.
  5. 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.
  6. So we output "No.".
  7.  
  8. 题意大体是 询问出栈入栈是否符合栈的规定,如果符合 输入顺序;否则no。最后finsh
  9.  
  10. 代码
  1. #include<cstdio>
  2. #include<cstdlib>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<vector>
  6. #include<queue>
  7. #include<stack>
  8. #include<set>
  9. #include<iostream>
  10. #include<bits/stdc++.h>
  11. #define ll long long
  12. using namespace std;
  13. int n,i,j,k,flag[];
  14. char s1[],s2[];
  15. int main()
  16. {
  17. stack <char> s;
  18. while(~scanf("%d",&n)){
  19. memset(flag,-,sizeof(flag));
  20. cin>>s1>>s2;
  21. while(!s.empty()) s.pop();
  22. j=,k=;
  23. for(int i=;i<n;i++){
  24. s.push(s1[i]);
  25. flag[k++]=;
  26. while(!s.empty()&&s.top()==s2[j])
  27. flag[k++]=,s.pop(),j++;
  28. }
  29. if(j==n){
  30. printf("Yes.\n");
  31. for(int i=;i<k;i++)
  32. if(flag[i]) printf("in\n");
  33. else printf("out\n");
  34. printf("FINISH\n");
  35. }else{
  36. printf("No.\n");
  37. printf("FINISH\n");
  38. }
  39. }
  40. return ;
  41. }

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. UI复习

    UIButton的状态 • normal(普通状态) ➢ 默认情况 ➢ 对应的枚举常量:UIControlStateNormal • highlighted(高亮状态) ➢ 按钮被按下去的时候(手指还 ...

  2. iOS-UIScrollView和UIPageControl的综合实力,滚动图,轮播图

    本代码主要实现图片之间的切换 目录结构 代码 ViewController.m文件 #import "ViewController.h" @interface ViewContro ...

  3. JSP中request getParameter和getAttribute不同(转载)

    (1)request.getParameter()取得是通过容器的实现来取得通过类似post,get等方式传入的数据,,request.setAttribute()和getAttribute()只是在 ...

  4. Asp.net WebPages框架运行原理浅析(转)

    在Asp.net4和4.5中,新增了WebPages Framework,编写页面代码使用了新的Razor语法,代码更加的简洁和符合Web标准,编写方式更接近于PHP和以前的Asp,和使用 WebFo ...

  5. mysql一些小技巧

    1 强制命中索引:force index 某些时候查询,索引会失效,可以进行强制命中索引 2 group_concat 能将相同的行组合起来. 当然,我推荐这种操作可以在代码中操作,如果必须在特定情况 ...

  6. 基于分布式、服务化的maven项目文件规划

    引言 此文不是纯粹介绍maven概念,而是介绍一个具体的maven项目文件规划 这个规划可能适合于研发比较复杂的业务,这些业务有分布式和服务化的需要. 这个规划能够解决因为分布式和服务化要求而引起的项 ...

  7. PMBOK(第五版)学习笔记二-十大知识领域(P87)

    五大项目管理过程组:启动.规划.执行.监控.收尾过程组 十大知识领域是:项目整合管理.项目范围管理.项目时间管理.项目成本管理.项目质量管理.项目人力资源管理.项目沟通管理.项目风险管理.项目采购管理 ...

  8. C#语言基础-类——string增加内容

    .split()    分离——属于string类            Console.Write("请输入姓名和学号(**-****):");            strin ...

  9. 挖一挖C#中那些我们不常用的东西之系列(3)——StackTrace,Trim

    时间太快了,三月又要过去了,告别一下...继续期待生死未卜的四月,今天我们继续挖一挖. 一: Environment.StackTrace 可能我们看到最多的就是catch中的e参数,里面会有一个St ...

  10. Windows下用Codeblocks建立一个最简单的DLL动态链接库

    转自:http://blog.csdn.net/wangwei_cq/article/details/8187576 来源:http://hi.baidu.com/hellosim/item/9ae4 ...