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 ...
随机推荐
- MySQL对NULL值的处理
mysql: 我们已经知道MySQL使用 SQL SELECT 命令及 WHERE 子句来读取数据表中的数据,但是当提供的查询条件字段为 NULL 时,该命令可能就无法正常工作. 为了处理这种情况,M ...
- 中兴电信光纤猫F450获取管理员密码方法
初衷:为了完成端口映射,一开始以为电信光猫不支持自定义路由,因为通过useradmin登录进去后没有找到对应的选项.一番了解之后,原来光猫有超级密码,电信装机时是不会告诉你的,电信客服一般也不会告诉你 ...
- linux 下查看cpu是几核的
几个cpu more /proc/cpuinfo |grep "physical id"|uniq|wc -l 每个cpu是几核(假设cpu配置相同) more /proc/cpu ...
- 【IE6的疯狂之九】li在IE中底部空行的BUG
曾经写过[IE6的疯狂之六]li在IE中底部3像素的BUG(增加浮动解决问题),原文地址:http://www.css88.com/archives/421: IE6 BUG大全: http://ww ...
- ap143 led修改
以前的硬件版本只使用了一个eth口,新的板子增加了一个eth口,并且增加了响应的通信时使用的灯. led修改涉及到一下的内容: (1)led 对应的gpio口(这个需要根据原理图来定义) 需要修改的源 ...
- linux kernel module
#include <linux/init.h>#include <linux/module.h>#include <linux/kernel.h> static i ...
- Java线程小记
线程是程序内部不同的执行分支,实现多线程主要有两种方式:继承自Thread类或实现Runnable接口,其实Thread类也是实现了Runnable接口,基于Java的单继承机制,我们建议使用实现Ru ...
- Jquery中日期插件jquery.datepick的使用
jsp的代码: <%@ page language="java" contentType="text/html; charset=UTF-8" pageE ...
- ansible role 执行顺序
the dependencies of the 'openshift-master' role.- docker- openshif_common - os_firewall - openshi ...
- css3学习01
1.圆角边框(div的一个属性:border-radius) <!DOCTYPE html> <html> <head> <style> div { t ...