hdu 1022 Train Problem I 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1022
又是一道栈的练习,这次也是没有用到STL中的栈来实现。用来保存操作过程的数组(process[])一定要开得足够大(一开始开小了导致wa)
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std; const int maxn = ;
int main()
{
char o1[maxn], o2[maxn], stack[maxn];
int i, j, n, a, b, k, process[];
while (scanf("%d", &n) != EOF)
{
scanf("%d%d", &a, &b);
sprintf(o1, "%d", a); // 把整型的a、b转化成字符串,当然这里可以直接在第11行中写成while(scanf("%d%s%s", &n, o1, o2) != EOF)
sprintf(o2, "%d", b);
// cout << "o1 = " << o1 << endl;
// cout << "o2 = " << o2 << endl;
int top = ;
int ok = ;
k = i = j = ;
memset(process, , sizeof(process));
while (j < n)
{
/* if (o1[i] == o2[j])
{
i++;
j++;
} */ // 如果进栈和出栈的顺序刚好相同,则省去不必要的进栈和出栈操作,不过这里为了缩短代码所以干脆注释掉
if (top && stack[top] == o2[j])
{
top--;
j++;
process[k] = ; // 保存出栈操作out
}
else if (i < n)
{
stack[++top] = o1[i++];
process[k] = ; // 保存进栈操作in
}
else
{
ok = ;
break;
}
k++;
}
if (ok)
{
printf("Yes.\n");
for (i = ; i < k; i++)
{
printf("%s\n", (process[i] ? "in" : "out"));
}
}
else
printf("No.\n");
printf("FINISH\n");
}
return ;
}
hdu 1022 Train Problem I 解题报告的更多相关文章
- 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
A - Train Problem I Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- 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【栈的应用】【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
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
随机推荐
- BZOJ-1880 Elaxia的路线 SPFA+枚举
1880: [Sdoi2009]Elaxia的路线 Time Limit: 4 Sec Memory Limit: 64 MB Submit: 921 Solved: 354 [Submit][Sta ...
- groovy–流程控制
在本篇文章中,我们将介绍逻辑分支,循环,以及如何从if-else以及try-catch代码块中返回值. if – elseGroovy 支持Java传统的if-else语法: def x = fals ...
- [Python] Python 之 __new__() 方法与实例化
__new__() 是在新式类中新出现的方法,它作用在构造方法建造实例之前,可以这么理解,在 Python 中存在于类里面的构造方法 __init__() 负责将类的实例化,而在 __init__() ...
- Eigenvectors and eigenvalues
http://setosa.io/ev/eigenvectors-and-eigenvalues/ Explained Visually Tweet By Victor Powell and Lew ...
- Solr之搭建Solr5.2.1服务并从Mysql上导入数据
原文地址:http://www.bkjia.com/webzh/1026243.html
- 部署在IIS上的网站如何调试
引言 今天突然有个朋友问我,总听同事说在IIS中如何如何调试,到底如何调试呢?没办法,人家刚入门,还是亲手给他操作了一遍.也记录一下,希望能帮到那些不知道的孩纸. IIS中的网站调试 调试最常见的一般 ...
- linux的设置ip连接crt,修改主机名,映射,建文件
1.修改IP(或者vim vi /etc/sysconfig/network-scripts/ifcfg-eth0) 2.连接 crt 3.修改主机名 用vim 编辑 /etc/sysconfig/n ...
- (三)Linux命令基本格式以及文件处理命令
命令基本格式 (1)命令提示符 如下是命令行的命令提示符,以此为例,讲解含义. 其中: root 当前登录用户名 localhost 主机名 ~ 当前所在的目录(即家目录,用户登录的初始位置) # 超 ...
- github和bitbucket
注册一个github跟注册一个163的邮箱一样容易 页面中 div方块的 布局和 尺寸, 主要是考虑功能/ 结构/布局, 基本上与其中的内容 的多少无关: 即使内容/文字很少, 也还是要那么宽的尺寸 ...
- spring 注解的总结
一.java内置注解 1.@Target 表示该注解用于什么地方,可能的 ElemenetType 参数包括: ElemenetType.CONSTRUCTOR 构造器声明 ElemenetTyp ...