HDU 1022 Train Problem I(栈模拟)
Description



Input
Output
Sample Input
3 123 321 3 123 312
Sample Output
Yes.in in in out out out FINISH No. FINISH
思路
#include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
const int maxn = 15;
int main()
{
int N;
while (~scanf("%d",&N))
{
bool flag = true;
stack<int>stk;
int i,inout[maxn] = {0},in[maxn],out[maxn];
char sin[maxn],sout[maxn];
scanf("%s %s",sin,sout);
for (i = 0;i < N;i++) in[i] = sin[i] - '0';
for (i = 0;i < N;i++) out[i] = sout[i] - '0';
// for (i = 0;i < N;i++) printf("%d %d\n",in[i],out[i]);
int j = 0,p = 0;
i = 0;
for (i = 0;i < N;i++)
{
if (in[i] != out[j])
{
inout[p++] = 0;
stk.push(in[i]);
}
else if (in[i] == out[j])
{
inout[p++] = 0;
j++;
inout[p++] = 1;
while (!stk.empty() && stk.top() == out[j])
{
j++;
inout[p++] = 1;
stk.pop();
}
}
}
while (!stk.empty())
{
if (stk.top() != out[j])
{
flag = false;
break;
}
else
{
j++;
stk.pop();
inout[p++] = 1;
}
}
if (!flag) printf("No.\nFINISH\n");
else
{
printf("Yes.\n");
for (i = 0;i < p;i++) inout[i]?printf("out\n"):printf("in\n");
printf("FINISH\n");
}
}
return 0;
}
/*
5
12342 24321
*/
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)T ...
- 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 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【栈的应用】【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(数据结构,栈,递归,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 ...
随机推荐
- Struts2 动态结果和带参数的跳转
完整代码:Struts16ActionResultsDemo.rar 1.动态结果. 有时我们需要在Action里取得我个要转跳的页面 看一下我们的struts.xml <?xml versio ...
- [转]Android中Xposed框架篇—利用Xposed框架实现拦截系统方法
一.前言 关于Xposed框架相信大家应该不陌生了,他是Android中Hook技术的一个著名的框架,还有一个框架是CydiaSubstrate,但是这个框架是收费的,而且个人觉得不怎么好用,而Xpo ...
- Windows Phone 8 下载文件进度
后台代码: public partial class MainPage : PhoneApplicationPage { private long siz; private long speed; p ...
- 阅读DNA-2014年读书
- redis+Keepalived主从热备秒级切换
一 简介 安装使用centos 5.10 Master 192.168.235.135 Slave 192.168.235.152 Vip 192.168.235.200 编译环境 yum -y in ...
- 在stream流和byte[]中查找(搜索)指定字符串
在 stream流 和 byte[] 中查找(搜索)指定字符串 这里注重看的是两个 Search 的扩展方法,一个是 stream 类型的扩展,另一个是 byte[] 类型的扩展, 如果大家有更好的“ ...
- Day Seven(Beta)
站立式会议 站立式会议内容总结 331 今天: 1)阅读html 5+文档 未来走h5路线 2)restful,未来开发接口 3)h5+demo运行 4)get 代码:a||(a=as); 5)js ...
- IntelliJ idea的使用
1.快捷键 2.插件集成 附录:参考资料
- SpringMVC学习--参数绑定
spring参数绑定过程 从客户端请求key/value数据,经过参数绑定,将key/value数据绑定到controller方法的形参上.springmvc中,接收页面提交的数据是通过方法形参来接收 ...
- 任意文件夹下打开cmd功能的设置(win10)
win10中打开cmd的方法: 1."运行"中输入CMD打开,也可以按住win+R 2.选择命令行工具中"开始-->>所有应用-->>Window ...