hdu 1022 Train Problem I(栈)
#include<iostream>
#include<vector>
#include<cstring>
#include<string>
#include<stack>
#include<map>
using namespace std;
];
/*
栈的应用
若in[i]==out[j]则先进栈后立即出栈,此时只需i++,j++;
若in[i]!=out[j]检查栈首是否为out[j],若是,则出栈,并j++,否则将in[i]入栈,并j++
i==n时,若栈不为空则说明任有火车未出栈,检查栈内元素==out[j++] f[i]: 1表示进栈,0表示出栈
。。。。期末考试时不会做,遂记之
*/
int main()
{
freopen("d:\\in.txt", "r", stdin);
freopen("d:\\out.txt", "w", stdout);
string in, out;
int n;
while(cin>>n)
{
;
cin>>in>>out;
bool flag=true;
, j=;
stack<char>s;
while(i<n) {
if(in[i]==out[j]){
i++; j++;
f[cur++]=;
f[cur++]=;
}else if(!s.empty()){
char first=s.top();
if(first==out[j]){
j++;
s.pop();
f[cur++]=;
}else{
s.push(in[i++]);
f[cur++]=;
}
}else {
s.push(in[i++]);
f[cur++]=;
}
}
while(!s.empty()){
char first=s.top();
f[cur++]=;
s.pop();
if(first != out[j++]){
flag=false;
break;
}
}
if(flag){
cout<<"Yes."<<endl;
; i<cur; i++){
)cout<<"in"<<endl;
else cout<<"out"<<endl;
}
cout<<"FINISH"<<endl;
} else {
cout<<"No.\nFINISH"<<endl;
}
}
;
}
hdu 1022 Train Problem I(栈)的更多相关文章
- Hdu 1022 Train Problem I 栈
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1022 Train Problem I(栈的操作规则)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1022 Train Problem I Time Limit: 2000/1000 MS (Java/Ot ...
- hdu 1022 Train Problem I【模拟出入栈】
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- 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 ...
- HDU - 1022 Train Problem I STL 压栈
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1022 Train Problem I(栈的应用+STL)
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1022:Train Problem I(数据结构,栈,递归,dfs)
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- HDU 1022 Train Problem I[给出两个长n的串,入栈和出栈顺序,判断入栈顺序是否可以匹配出栈顺序]
Train Problem I 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 As the new term comes, the Ignatius Train Sta ...
- HDU 1022 Train Problem I
A - Train Problem I Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- hdu 1022 Train Problem
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
随机推荐
- HDU 2045 不容易系列之(3)—— LELE的RPG难题(递归/动态规划)
不容易系列之(3)—— LELE的RPG难题 Problem Description 人称“AC女之杀手”的超级偶像LELE最近忽然玩起了深沉,这可急坏了众多“Cole”(LELE的粉丝,即" ...
- android 界面布局
一.LinearLayout LinearLayout 又称作线性布局,是一种非常常用的布局,它所包含的控件在线性方向上依次排列. android:orientation="horizont ...
- hibernate、easyui、struts2整合
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- CodeForces 708B Recover the String
构造. 根据$a[0][0]$可以求得$0$的个数$p$,根据$a[1][1]$可以求得$1$的个数$q$. 如果找不到$p$或$q$,那么就无解. 每一个$0$放到序列中的任何一个位置,假设和前面的 ...
- GL应用方面
1.图和表 2.计算机辅助设计CAD 3.虚拟现实环境 4.数据可视化 5.教学与培训(基于VR) 6.计算机艺术 7.娱乐 8.图像处理 9.用户界面
- 【hihoCoder 1466】后缀自动机六·重复旋律9
http://hihocoder.com/problemset/problem/1466 建出A串和B串的两个后缀自动机 对后缀自动机的每个状态求出sg值. 求出B串的\(sum(x)\),表示B有多 ...
- jmeter命令行运行-分布式测试
上一篇文章我们说到了jmeter命令行运行但是是单节点下的, jmeter底层用java开发,耗内存.cpu,如果项目要求大并发去压测服务端的话,jmeter单节点难以完成大并发的请求,这时就需要对j ...
- MVC之联动学习
一,数据库表设计 CREATE TABLE [dbo].[HY_Province]( [id] [INT] NOT NULL, [province] [NVARCHAR]() NOT NULL, CO ...
- select与ajax结合
要实现的功能是,点击select输入框,数据库里面的数据会以option弹出. 这需要用到ajax异步连接数据库 下面贴出代码 先说明一下后台传递的数据是json,以map的形式传入的.后台代码很简单 ...
- Xcode使用小结2
刷新时间慢的时候用timer定时器 以下内容为借用,作者:FlyElephant出处:http://www.cnblogs.com/xiaofeixiang iOS开发-NSOperation与GCD ...