Train Problem I

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

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

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.".

 
Author
Ignatius.L
 
栈的应用....
何为栈.....像一个瓶子....同一端进,同一端出....
//用到的头文件
#include<stack>
//声明
stack<type> s; s.push() ; //入栈;
s.top() ; //提起顶端元素
s.pop() ; //删除顶端元素
s.empty() ; //判断是否为空
s.size() ; // 栈的大小

此题纯属模拟即可轻松过....

代码:

 #include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
int main()
{
int n,i;
while(cin>>n)
{ stack<char> s;
bool c[];
int rank=,step=;
char a[],b[];
scanf("%s %s",b,a);
for(i=;i<n;i++)
{
if(a[rank]==b[i])
{
/*false---》进栈,true---》出栈*/
c[step++]=false;
c[step++]=true;
rank++;
}
else
{
while(!s.empty())
{
if(a[rank]==s.top())
{
rank++;
s.pop();
c[step++]=true;
}
else break;
}
s.push(b[i]);
c[step++]=false;
}
}
while(rank<n&&a[rank]==s.top())
{
rank++;
s.pop();
c[step++]=true;
}
if(!s.empty())
{
printf("No.\n");
}
else
{
puts("Yes.");
for(i=;i<*n;i++)
{
if(c[i])
puts("out");
else
puts("in");
}
}
puts("FINISH");
}
return ;
}

HDUOJ-------(1022)Train Problem I的更多相关文章

  1. (stack)Train Problem I hdu1022

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

  2. (母函数 Catalan数 大数乘法 大数除法) Train Problem II hdu1023

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

  3. HDU 1022 之 Train Problem I

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

  4. 2016中国大学生程序设计竞赛(长春) Ugly Problem 模拟+大数减法

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5920 我们的思路是: 对于一个串s,先根据s串前一半复制到后一半构成一个回文串, 如果这个回文串比s小, ...

  5. 形式化验证工具(PAT)Reader-Writers Problem学习

    经过前几次的学习,我们应该对PAT有一点点的了解了,我们加下来就直接看例子中的一个问题,这个问题比较简单. 看代码: //The classic Readers/Writers Example mod ...

  6. (算法)Hanoi Problem汉诺塔问题

    Problem: There are three poles and N disks where each disk is heaver than the next disk. In the init ...

  7. Caffe初试(三)使用caffe的cifar10网络模型训练自己的图片数据

    由于我涉及一个车牌识别系统的项目,计划使用深度学习库caffe对车牌字符进行识别.刚开始接触caffe,打算先将示例中的每个网络模型都拿出来用用,当然这样暴力的使用是不会有好结果的- -||| ,所以 ...

  8. LARC Caffe笔记(二) 训练自己的img

    继看完 贺完结!CS231n官方笔记 上一次已经成功跑起caffe自带的例程,mnist和cifar10 但是终归用的是里面写好的脚本,于是打算训练自己的img 〇.目标 准备好food图片3类(出于 ...

  9. CAFFE学习笔记(五)用caffe跑自己的jpg数据

    1 收集自己的数据 1-1 我的训练集与测试集的来源:表情包 由于网上一幅一幅图片下载非常麻烦,所以我干脆下载了两个eif表情包.同一个表情包里的图像都有很强的相似性,因此可以当成一类图像来使用.下载 ...

随机推荐

  1. IOS tableview 横向滚动

    1. UITableView 设置 CGRect tableViewRect = CGRectMake(0.0, 0.0, 50.0, 320.0);self.tableView = [[UITabl ...

  2. Eclipse中运行Tomcat遇到的内存溢出错误

    使用Eclipse(版本Indigo 3.7)调试Java项目的时候,遇到了下面的错误: Exception in thread "main" Java.lang.OutOfMem ...

  3. 深入理解Java中的组合和继承

    Java是一个面向对象的语言.每一个学习过Java的人都知道,封装.继承.多态是面向对象的三个特征.每个人在刚刚学习继承的时候都会或多或少的有这样一个印象:继承可以帮助我实现类的复用.所以,很多开发人 ...

  4. C/C++中内联(inline)函数的优点和缺点

    优点 缺点 1. 内联函数代码被放入符号表中,在使用时进行替换,和宏展开一样,效率很高: 1. 不允许过多的代码,代码过多的话会造成大的内存消耗,最好在5行以内: 2. 编绎器在调用一个内联函数,首先 ...

  5. Observer 观察者模式 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  6. eclipse无法解析导入 java.util

    eclipse无法解析导入 java.util是因为jre配置错误. 1.点击需要导入jar的项目,右击项目属性(properties),进入到如下图界面: 2.选择Java Build Path选项 ...

  7. Jquery解析Json格式数据

    今天稍微学习了一下Json,JSON (JavaScript Object Notation) 是一种轻量级的数据交换格式. 易于人阅读和编写.同时也易于机器解析和生成. JSON采用完全独立于语言的 ...

  8. Idea代码可视化插件

    Idea代码可视化插件 https://plugins.jetbrains.com/plugin/7324-code-iris

  9. RS交叉表自动汇总后百分比列显示错误之解决方案

    可以说在从事Cognos开发的过程中,仅仅对数据展现而言,大多数用户使用最多的工具便是Report Studio了,此工具可以帮助我们快速的构建一些可供用户自主选择的数据报告.当然我个人认为没有什么开 ...

  10. js 继承概述

    上文讲述过js实现面向对象,一定是能够实现继承的效果的.尽管说非常多的js框架都帮助我们实现了继承的功能.或者说在日常的工作和学习中我们压根就用不到js的继承,可是我们还是须要了解一下js中继承.以方 ...