题目链接: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. 【POJ 3176】Cow Bowling

    题 Description The cows don't use actual bowling balls when they go bowling. They each take a number ...

  2. ThinkPHP多表联合查询的常用方法

    1.原生查询示例: $Model = new Model(); $sql = 'select a.id,a.title,b.content from think_test1 as a, think_t ...

  3. linux内核数据结构学习总结

    目录 . 进程相关数据结构 ) struct task_struct ) struct cred ) struct pid_link ) struct pid ) struct signal_stru ...

  4. Type-Length-Value编码

    Within data communication protocols, optional information may be encoded as a type-length-value or T ...

  5. HDU 2896

    传送门:HDU 2896 病毒侵袭 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  6. java + jquery + ajax + json 交互

    前端js部分: $.ajax({ async:true, cache:false, type:"POST", dataType : 'json', url:"/shopp ...

  7. The C Programming Language (second edition) 实践代码(置于此以作备份)

    1. #include <stdio.h> #include <stdlib.h> #include <math.h> #include<time.h> ...

  8. 周期串(Periodic Strings,UVa455)

    解题思路: 对一个字符串求其最小周期长度,那么,最小周期长度必定是字符串长度的约数,即最小周期长度必定能被字符串长度整除 其次,对于最小周期字符串,每位都能对应其后周期字串的每一位, 即 ABC  A ...

  9. CruiseControl.NET学习总结(转载)

    前些日子,总结了一个NAnt的学习总结.后来就放下了,松散了一阵子.CruiseControl.NET(以下称CC.NET),是我在学习完NAnt以后才开始看的,当时学起来就是在网上疯狂的找资料.现在 ...

  10. ORA-00931: missing identifier ORA-06512: at "SYS.DBMS_UTILITY"

    Database db = DatabaseFactory.CreateDatabase();            string sql = "SELECT * FROM table&qu ...