传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1022

Train Problem I

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

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
 
Recommend
We have carefully selected several similar problems for you:  1026 1023 1020 1032 1001 
 
分析:
此题不真正的仔细读难理解出事栈的应用,容易想成反序相等就yes的问题,此题题意是说输入的两列字符串,第一列表示进入的顺序,第二列表示出去的顺序,问你是否符合后进先出。

举出一列数据 7 1234567 4321576
上面数据应该是 in in in in out out out out in out in in out out;

所以不是反序才行 可以进到一半就出的

 
stl就是好用啊!
 
code:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
int n,i,j;
string str1,str2;
while(cin>>n>>str1>>str2)
{
stack<char> s;
vector<string> v;
for( i=,j=;i<n&&j<n;i++)
{
s.push(str1[i]);//元素进栈
v.push_back("in");//字符压进容器
while(s.top()==str2[j])//匹配
{
if(!s.empty())
{
s.pop();
v.push_back("out");
}
j++;
if(s.empty())
break;
}
}
if(j==n)//判断依据
{
printf("Yes.\n");
for(i=;i<v.size();i++)
cout<<v[i]<<endl;
cout<<"FINISH"<<endl;
}else
{
cout<<"No."<<endl<<"FINISH"<<endl;
}
}
return ;
}

HDU 1022 Train Problem I(栈的操作规则)的更多相关文章

  1. Hdu 1022 Train Problem I 栈

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

  2. hdu 1022:Train Problem I(数据结构,栈,递归,dfs)

    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)T ...

  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[给出两个长n的串,入栈和出栈顺序,判断入栈顺序是否可以匹配出栈顺序]

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

  8. HDU 1022 Train Problem I 模拟栈题解

    火车进站,模拟一个栈的操作,额外的栈操作,查看能否依照规定顺序出栈. 数据量非常少,故此题目非常easyAC. 直接使用数组模拟就好. #include <stdio.h> const i ...

  9. HDU 1022 Train Problem I

    A - Train Problem I Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

随机推荐

  1. logback.xml简单配置

    感觉配置的没问题,但是控制台就是不输出日志,后来发现是jar的问题. 依赖包: 注意依赖包,没有其他,只有下面3个,因为Jar包的问题,浪费了很长时间 <dependency> <g ...

  2. Effective C++ .14 智能指针的拷贝与deleter函数

    #include <iostream> #include <cstdlib> #include <memory> using namespace std; clas ...

  3. HTML语言中img标签的alt属性和title属性的作用与区别

    alt属性是在你的图片因为某种原因不能加载时在页面显示的提示信息,它会直接输出在原本加载图片的地方,而title属性是在你鼠标悬停在该图片上时显示一个小提示,鼠标离开就没有了,有点类似jQuery的h ...

  4. Java类——JDBC链接、并操作MySQL数据库

    Java——MySQL数据库操作类 package pkg.src.database; import java.sql.*; public class MYSQL_DBManager { // //定 ...

  5. python 进程池的使用

    进程同步 进程的数据是独立存在的,进程也能加锁. from multiprocessing import Process, Lock def f(l,i): l.acquire() print('he ...

  6. According to TLD, tag fmt:formatDate must be empty, but is not 问题的解决

    在执行jsp格式化后报错,检查下代码,发现变成如下的样式: <fmt:formatDate value="${cur.sa_date}" pattern="yyyy ...

  7. 微信小程序支付返回信息为空

    1.昨天公司说要实现微信小程序的支付,于是看了下微信小程序的开发api文档,和之前的app  端以及pc端基本相似:于是让他们把参数改了下,把之前的trade_type 由 app 改成 小程序要求的 ...

  8. 使用C3的一些新属性绘制谷歌浏览器的图标

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  9. Java—IO流 字符流

    java的文本(char)是16位无符号整数,是字符的unicode编码(双字节编码). 文件是byte byte byte ... 的数据序列. 文本文件是文本(char)序列按照某种编码方案(uf ...

  10. 如何判断单链表是否存在环 & 判断两链表是否相交

    给定一个单链表,只给出头指针h: 1.如何判断是否存在环? 2.如何知道环的长度? 3.如何找出环的连接点在哪里? 4.带环链表的长度是多少? 解法: 1.对于问题1,使用追赶的方法,设定两个指针sl ...