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 ...
随机推荐
- 【CodeForces 618C】Constellation
题 Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars n ...
- BZOJ-3576 江南乐 博弈+优化
fye测试原题,高一全跪,高二学长除了CA爷似乎都A辣(逃) 3576: [Hnoi2014]江南乐 Time Limit: 30 Sec Memory Limit: 512 MB Submit: 1 ...
- 【bzoj1013】 JSOI2008—球形空间产生器sphere
www.lydsy.com/JudgeOnline/problem.php?id=1013 (题目链接) 题意 有一个n维的球体,给出球上n+1个点,求出圆心. Solution 题中给出了对于n维空 ...
- 利用symbolsource/gitlink调试你的nuget包
关键字: 如何调试Nuget下载的dll? VS github 调试 参考文章: http://docs.nuget.org/create/creating-and-publishing-a-sy ...
- groovy-运算符
算术和条件运算符 Groovy支”!”操作符,例如: 1 def expression = false 2 assert !expression 基于集合的运算符: Spread Operator ( ...
- C++中使用array报错 requires compiler and library surpport for the ISO c++ 2011 standard
#error This file requires compiler and library support for the \ISO C++ 2011 standard. This support ...
- Servlet------(声明式)异常处理
Test.java 其他方法不变,重写 protected void service()方法 public void init(ServletConfig config) throws Servlet ...
- spring属性依赖注入
一.构造方法方式注入 1.项目结构如下: 2.新建Customer类 package hjp.spring.attributeinject; public class Customer { priva ...
- Hbase Shell常用命令
hbase shell常用的操作命令有create,describe,disable,drop,list,scan,put,get,delete,deleteall,count,status等,通过h ...
- Dedecms v5.7 最新注入分析
该漏洞是cyg07在乌云提交的, 漏洞文件: plus\feedback.php.存在问题的代码: view source 01 ... 02 if($comtype == 'comments') 0 ...