hdu 1022
// hdu1022
这题算是我做的第一道栈的题目,之前看过栈的一些内容,做这道题的时候,可以模拟出过程,但是具体的代码不会写。。。所以决定练习一些栈和队列的问题,大概思路就是有三个数组和一个栈,先把第一个数组的第一个元素放进栈里,每次判断第二个数组和栈顶元素是否相等,如果相等就弹出,如果不相等就压入,大概就是这个思路。。。。
#include <iostream>
#include <stack>
using namespace std;
int main()
{
stack<char>s;
int n;
char a[100],b[100];
while(cin>>n>>a>>b)
{
int i=1,j=0,flag[100],k=1;
s.push(a[0]);
flag[0]=0;
while(i<n+1&&j<n)
{
if(s.size()!=0&&s.top()==b[j])
{
j++;
s.pop();
flag[k++]=1;
}
else
{
if(i==n+1) break;
s.push(a[i++]);
flag[k++]=0;
}
//cout<<i<<endl;
}
//cout<<i<<" "<<j<<endl;
if(i==n+1)
cout<<"No.\n";
else
{cout<<"Yes.\n";
for(i=0;i<k;i++)
if(flag[i]==1)
cout<<"out\n";
else
cout<<"in\n";}
cout<<"FINISH\n";
}
return 0;
}
hdu 1022的更多相关文章
- HDU 1022 Train Problem I
A - Train Problem I Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- Train Problem I hdu 1022(栈)
http://acm.split.hdu.edu.cn/showproblem.php?pid=1022 题意:给出火车的进站与出站顺序,判断是否可以按照给出的出站顺序出站. #include < ...
- hdu 1022 Train Problem I 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1022 又是一道栈的练习,这次也是没有用到STL中的栈来实现.用来保存操作过程的数组(process[] ...
- HDU 1022 火车进站【栈】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1022 题目大意: 题目大概意思:有N辆火车,以序列1方式进站,判断是否能以序列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 ...
- 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(栈模拟)
传送门 Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of st ...
- 栈的简单应用 HDU 1022 http://acm.hdu.edu.cn/showproblem.php?pid=1022
#include<stdio.h> #include<stack> #include<string.h> #define N 20 using namespace ...
- HDOJ/HDU 1022 Train Problem I(模拟栈)
Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot o ...
随机推荐
- 08_linux下安装chrome
首先下载chrome,需要改hosts哦(o(^▽^)o,别告诉我你不会,可以问度娘.谷哥哦) 下载地址:https://dl.google.com/linux/direct/google-chrom ...
- JS类型判定方法(不包括自定义类型)
//判定数据类型 function isType(obj, type) { return toString.call(obj).indexOf('[object ' + type) == 0; } / ...
- [转]JS继承的5种实现方式
参考链接: http://yahaitt.iteye.com/blog/250338 虽说书上都讲过继承的方式方法,但这些东西每看一遍都多少有点新收获,所以单独拿出来放着. 1. 对象冒充 funct ...
- Java System类
java 不支持 全局方法 和 变量, system 类 中所有成员都是静态的, 而要引用这些变量和方法,可直接system作为前缀,
- 001Spark文件分析测试
使用spark-1.4.1-bin-hadoop2.6进行处理,测试文件大小为3G, 测试结果: 1:统计一个文件中某个字符的个数 scala> sc.textFile("/home/ ...
- javascript note
boolean("false") =====>true Date(1387123200000)不等于new Date(1387123200000) 用Date(1387123 ...
- (?m) 可以让.去匹配换行
<pre name="code" class="html"># User@Host: zjzc_app[zjzc_app] @ [10.171.24 ...
- Borg Maze(bfs+prim)
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6971 Accepted: 2345 Description The B ...
- HDOJ 2131 Probability
Problem Description Mickey is interested in probability recently. One day , he played a game which i ...
- 解读sample5
说明 被测试代码文件 sample1.h.sample1.cc和sample3-inl.h 测试代码文件 sample5_unittest.cc 官网上如是描述sample5: Sample #5 i ...