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 ...
随机推荐
- 区块链~Merkle Tree(默克尔树)算法解析~转载
转载~Merkle Tree(默克尔树)算法解析 /*最近在看Ethereum,其中一个重要的概念是Merkle Tree,以前从来没有听说过,所以查了些资料,学习了Merkle Tree的知识,因为 ...
- mssql注入中的储存用法删除与恢复
删除: use master exec sp_dropextendedproc 'xp_cmdshell' exec sp_dropextendedproc 'xp_enumgroups' exec ...
- perl发送post数据
把post数据写进一个匿名数组里就行 #!/usr/bin/env perl -w use strict; use LWP::UserAgent; my $ua = LWP::UserAgent-&g ...
- H264协议(转)
码率(Bitrate).帧率(FPS).分辨率和清晰度的联系与区别:https://blog.csdn.net/pc9319/article/details/79621352 H.264编码原理以及I ...
- python traceback
1. Python中的异常栈跟踪 之前在做Java的时候,异常对象默认就包含stacktrace相关的信息,通过异常对象的相关方法printStackTrace()和getStackTrace()等方 ...
- Java-贪心算法
1. 什么是贪心算法? 贪心算法,又称贪婪算法(Greedy Algorithm),是指在对问题求解时,总是做出在当前看来是最好的选择.也就是说,不从整体最优解出发来考虑,它所做出的仅是在某种意义上的 ...
- python代码实现dijkstra算法
求解从1到6的最短路径. python代码实现:(以A-F代表1-6) # Dijkstra算法需要三张散列表和一个存储列表用于记录处理过的节点,如下: processed = [] def buil ...
- Django视图之ORM更改数据库连接——配置MySQL库
Django中创建app01应用 python manage.py startapp app01 1. 首先安装pymsql模块 # Python3中 pip3 install pymysql 在 p ...
- Sort List——经典(链表中的归并排序)
Sort a linked list in O(n log n) time using constant space complexity. 对一个链表进行排序,且时间复杂度要求为 O(n lo ...
- matlab实用命令
实用命令 打点测时 在需要测量的开始部分标记: tic 在需要测量的结束部分标记: toc 记录程序从tic到toc运行所花费的时间 Image 翻转 fliplr(x) //左右翻转 flipud( ...