本题主要是出栈入栈顺序的问题

     
 
 
1022. Train Problem
 
 
Total: 2206 Accepted: 703
 
     
     
 
Time Limit: 1sec    Memory Limit:256MB
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
aaarticlea/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAARABIDASIAAhEBAxEB/8QAGAABAAMBAAAAAAAAAAAAAAAAAAMFBwT/xAAlEAACAQQCAQMFAAAAAAAAAAABAgMABAURBiESIjFBMjZxdbP/xAAYAQACAwAAAAAAAAAAAAAAAAAAAwEEBf/EABsRAQEAAgMBAAAAAAAAAAAAAAEAAgMEEyFh/9oADAMBAAIRAxEAPwDQeRW+SyVnctBIkiiScOk87qm0ciP0aZWA8dkEDZA2fcGPCWPI+PXkUt3GIcQjkyQxTGdtMrAhUVQO5CraVd/UB1pa7cnHmbaW5hjxEktoZJJGulnjChWYsT4lvLoHvr3B1vommvuQYaSe/jGSxrW9yXEiCWIiTe9eWohvs/LH8n5ocDh9jlnsER+zt+9wDE9G0uKWO4hSaGRJIpFDI6MCrKewQR7ilVfFPs7B/r4P5rStB8ZJW9KUqIlKUoi//9k=" alt="" /> Copy sample input to clipboard
3 123 321
3 123 312
Sample Output
Yes.
in
in
in
out
out
out
FINISH
No.
FINISH

Problem Source: 2012年期末机考(Pan)

 
     
代码:
 // Problem#: 8670
// Submission#: 2493920
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<stdio.h>
using namespace std;
int main() {
string in_ = "in";
string out_ = "out";
string finish = "FINISH";
string in;
string out;
int trains; while (scanf("%d", &trains) != EOF) {
cin >> in >> out;
stack<char> station;
vector<string> state;
for (int i = ; i < in.size(); i++) {
if (in[i] == out[]) {
state.push_back(in_);
state.push_back(out_);
out.erase(out.begin());
while (!station.empty()) {//关键一步
if (station.top() == out[]) {
state.push_back(out_);
out.erase(out.begin());
station.pop();
} else
break;
}
} else {
station.push(in[i]);
state.push_back(in_);
}
}
state.push_back(finish);
if (station.empty()) {
cout << "Yes." << endl;
for (int i = ; i < state.size(); i++)
cout << state[i] << endl;
} else
cout << "No." << endl << finish << endl;
}
return ;
}
 

sicily 1022. Train Problem的更多相关文章

  1. Problem : 1022 ( Train Problem I )

    做题思路必须很清晰啊....可以用数组存储in或out来着,第一次C++用string啊,效果还行 Problem : 1022 ( Train Problem I ) Judge Status : ...

  2. HDU 1022 Train Problem I(栈的操作规则)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1022 Train Problem I Time Limit: 2000/1000 MS (Java/Ot ...

  3. HDU 1022 Train Problem I

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

  4. hdu 1022 Train Problem I【模拟出入栈】

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

  5. Hdu 1022 Train Problem I 栈

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

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

  7. HDU - 1022 Train Problem I STL 压栈

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

  8. hdu 1022 Train Problem I(栈的应用+STL)

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

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

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

随机推荐

  1. 三星Galaxy S4(GT-I9500)获取ROOT权限教程(转)

    http://news.candou.com/2013-05-20/453695_1.shtml 获取root权限的方法

  2. 龙书(Dragon book) +鲸书(Whale book)+虎书(Tiger book)

    1.龙书(Dragon book)书名是Compilers: Principles,Techniques,and Tools作者是:Alfred V.Aho,Ravi Sethi,Jeffrey D. ...

  3. 提升GDI画图的效率

    假设我们要画一个坐标图,里面可能还需要画网络线.XY各个单位的值.曲线或直线等,可能的函数代码如下: void OnPaint () { CPaintDC dc (this); DrawXY (&am ...

  4. C/C++的参数传递机制

    近来公司招人较多,由此面试了非常多的C++程序员.面试时,我都会问到参数传递的相关问题,尤其侧重指针.因为指针毕竟是C/C++最重要的一个优势(在某种情况下也可以说是劣势).但其结果是,1/3的人基本 ...

  5. Quadtrees--四叉树

    Description A quadtree is a representation format used to encode images. The fundamental idea behind ...

  6. linux记录登录ip方法

    PS:Linux用户操作记录一般通过命令history来查看历史记录,但是如果因为某人误操作了删除了重要的数据,这种情况下history命令就不会有什么作用了.以下方法可以实现通过记录登陆IP地址和所 ...

  7. iOS - UI - UITableView

    1.UITableView 表格视图 服从数据源 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSIn ...

  8. unity中js脚本与c#脚本互相调用

    unity中js脚本与c#脚本互相调用   test1.js function OnGUI() { if(GUI.Button(Rect(25,25,100,30),"JS Call CS& ...

  9. 设置背景为白色,避免从A视图跳转到B视图的时候出现卡顿

    - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; }

  10. macOS10.12允许所有来源设置

    如何调出允许所有来源呢? 很简单一行命令搞定 调出允许所有来源 1.打开终端执行命令 sudo spctl --master-disable 2.你在打开偏好设置--> 安全与隐私   好了赶快 ...