Train Problem I(模拟栈)
题意:模拟栈,试问使用2个栈,能否使得串1变为串2
思路:模拟,经典问题,注意只要相同的元素放到栈顶后就不会再移动了,只需要考虑剩下的元素,因此每次只考虑一个元素的进入方式。
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
int n,pd[];
char s1[],s2[],s3[];
int main(){
while (scanf("%d %s %s",&n,s1,s2)!=EOF){
int t1=,t2=,i=,cnt=;s3[i]=s1[];pd[]=;
while (t1<n&&t2<n){
if (s3[i]==s2[t2]){
i--;cnt++;pd[cnt]=;t2++;
}else{
s3[++i]=s1[++t1];cnt++;pd[cnt]=;
}
}
if (i==){
printf("Yes.\n");
for (int i=;i<=cnt;i++)
if (pd[i]==) printf("out\n");else printf("in\n");
}else printf("No.\n");
printf("FINISH\n");
}
}
Train Problem I(模拟栈)的更多相关文章
- HDOJ/HDU 1022 Train Problem I(模拟栈)
Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot o ...
- HDU 1022 Train Problem I 模拟栈题解
火车进站,模拟一个栈的操作,额外的栈操作,查看能否依照规定顺序出栈. 数据量非常少,故此题目非常easyAC. 直接使用数组模拟就好. #include <stdio.h> const i ...
- hdu 1022 Train Problem I(栈的应用+STL)
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- Train Problem I--hdu1022(栈)
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(栈的操作规则)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1022 Train Problem I Time Limit: 2000/1000 MS (Java/Ot ...
- hdu1022 Train Problem I---模拟栈
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1022 题目大意: 车的进出站问题,先给出N个火车,再按序列一的方式进站,判断能否以序列二的方式出站,若 ...
- HDU 1022 Train Problem I(栈模拟)
传送门 Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of st ...
- HDU Train Problem I 1022 栈模拟
题目大意: 给你一个n 代表有n列 火车, 第一个给你的一个字符串 代表即将进入到轨道上火车的编号顺序, 第二个字符串代表的是 火车出来之后到顺序, 分析一下就知道这,这个问题就是栈, 先进后出吗, ...
- hdu 1022 Train Problem I(栈)
#include<iostream> #include<vector> #include<cstring> #include<string> #incl ...
随机推荐
- 探索ReactNative应用
本篇文章是我看AC2016腾讯前端技术交流大会后写的.写的不好,大家见谅啊. 一,什么是ReactNative? 简单来说就是可以用javascript来写APP了,而且性能还不错. 用JS写的话已经 ...
- linux===进程操作
ps -ef ps -aux|grep chat.js a:显示所有程序 u:以用户为主的格式来显示 x:显示所有程序,不以终端机来区分 kill -9 nohup python da.py & ...
- 64_l1
L-function-1.23-18.fc26.i686.rpm 13-Feb-2017 23:19 154562 L-function-1.23-18.fc26.x86_64.rpm 13-Feb- ...
- 菜鸟学习nodejs--Socket.IO即时通讯
https://blog.csdn.net/lovemenghaibin/article/details/51263774
- Bzoj-2301 [HAOI2011]Problem b 容斥原理,Mobius反演,分块
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2301 题意:多次询问,求有多少对数满足 gcd(x,y)=k, a<=x<=b ...
- myeclipse创建的项目发布不了文档
进入MyEclipse的工作目录下/.metadata/.plugins/org.eclipse.core.runtime/.settings/com.genuitec.eclipse.ast.dep ...
- vue知识点(1)
处理用户输入 v-on指令添加一个事件监听器 div id="app-5"> <p>{{ message }}</p> <button v-on ...
- puppet安装和配置
一.安装puppet准备 //安装准备 ,两台机器都要操作 . 两台机器 172.7.15.106 (server) 172.7.15.111 (client) . 关闭防火墙 setenforce ...
- 关于那些Android中不常用的设置属性
很多在manifest中的属性我们经常遗忘了它们,或者经常看到但又不是很明白它的作用.那么在这里我就拿了一些属性简单的解释一下,防止以后碰到却不知道其中的意思.不是很全,以后会断断续续的补充吧 一.a ...
- MySQL的读写分离---主从复制、主主复制
1.复制是基于BinLog日志 存在三种日志格式:Statement:存储Sql语句,存储日志量是最小的.有可能复制不一致Row:存储event数据,存储日志量大,但是不能很直接进行读取:Mixed: ...