题目链接: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 解题报告的更多相关文章

  1. HDU 1022 Train Problem I(栈的操作规则)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1022 Train Problem I Time Limit: 2000/1000 MS (Java/Ot ...

  2. HDU 1022 Train Problem I

    A - Train Problem I Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

  3. hdu 1022 Train Problem I【模拟出入栈】

    Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  4. Hdu 1022 Train Problem I 栈

    Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. 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 ...

  6. HDU - 1022 Train Problem I STL 压栈

    Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. hdu 1022 Train Problem I(栈的应用+STL)

    Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. hdu 1022:Train Problem I(数据结构,栈,递归,dfs)

    Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  9. hdu 1022 Train Problem

    Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

随机推荐

  1. BZOJ2535 [Noi2010]Plane 航空管制2

    Description 世博期间,上海的航空客运量大大超过了平时,随之而来的航空管制也频频发生.最近,小X就因为航空管制,连续两次在机场被延误超过了两小时.对此,小X表示很不满意. 在这次来烟台的路上 ...

  2. hdu1695 莫比乌斯反演

    莫比乌斯反演:可参考论文:<POI XIV Stage.1 <Queries>解题报告By Kwc-Oliver> 求莫比乌斯函数mu[i]:(kuangbin模板) http ...

  3. Weak is not weak,Strong is not strong

    问题 今天做浏览器Controller的时候,碰到了一个奇怪的问题:每次pop浏览器controller之后,等几秒,总会碰到类似下面的错误(其中的xxxController就是浏览器或继承他的子类C ...

  4. [Angularjs]视图和路由(三)

    写在前面 上篇文章主要介绍了路由中when方法的第二个参数,常见的几个属性,以及作用.本篇文章,将介绍和路由相关的几个常见的服务. 系列文章 [Angularjs]ng-select和ng-optio ...

  5. while循环问题(老师询问问题,学生回答。学生会了可以放学,或者老师讲了10遍,还是没有会的,被迫无奈也要放学。)

    string a=""; ;//声明一个变量,老师重新讲课的次数. && a != "yes") { Console.WriteLine(&qu ...

  6. cannot get gid for group ‘nobody’

    启动php-fpm /data1/server/php-cgi/sbin/php-fpm 错误[28-Mar-2012 11:15:01] ERROR: failed to open configur ...

  7. (转)win32Application和win32ApplicationConsole

    这几天在创建MFC项目时,常常遇到一下两个连接错误,例如: 1. LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _ma ...

  8. iOS开发之#iPhone6与iPhone6Plus适配#Xcode6.0/Xcode6.1上传应用过程中一些变动以及#解决方案#

    更新时间2014年11月13日  本博文创建时,只有Xcode6.0, Xcode6.0尝试多次,确实如此 之后在6.1版本经博主少量尝试,确实也有如下问题,现更新下博客! iOS8发布之后,苹果强制 ...

  9. java工具类包

    Hutool 提供丰富的java方法,其maven引用 <dependency> <groupId>com.xiaoleilu</groupId> <arti ...

  10. poj.1094.Sorting It All Out(topo)

    Sorting It All Out Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28762   Accepted: 99 ...