http://acm.hdu.edu.cn/showproblem.php?pid=1022

http://blog.csdn.net/swm8023/article/details/6902426此处分类题

hdu1022题copy代码

  1. #include<iostream>

  2. #include<stack>

  3. #define max 100

  4. using namespace std;

  5. int main()

  6. {

  7. stack<char>s;

  8. int n,i,j,k,result[max];//n为列车个数, result数组用来表示结果,1表示进栈。0表示出

  9. char str1[max],str2[max];//序列1和序列2

  10. while(cin>>n>>str1>>str2)

  11. {

  12. j=0,i=0,k=1;

  13. s.push(str1[0]);//为防止栈空,压一个进去

  14. result[0]=1;//记录进来了一个。

  15. while(i<n&&j<n)

  16. {

  17. if(s.size()&&s.top()==str2[j])

  18. {//如果栈顶元素与序列2当前的元素相等,则弹栈,序列2集团向后移一位。

  19. j++;

  20. s.pop();

  21. result[k++]=0;

  22. }

  23. else

  24. {//否则从序列1中取当前元素压入栈中。

  25. if(i==n)break;

  26. s.push(str1[++i]);

  27. result[k++]=1;

  28. }

  29. }

  30. if(i==n)//如果I==N表示栈顶元素不等于序列2当前元素,且序列1中元素都已经入过栈,判断不能得到序列2一样的答案。

  31. cout<<"No."<<endl;

  32. else

  33. {//输出进出栈方式

  34. cout<<"Yes."<<endl;

  35. for(i=0; i<k; i++)

  36. if(result[i])

  37. cout<<"in"<<endl;

  38. else

  39. cout<<"out"<<endl;

  40. }

  41. cout<<"FINISH"<<endl;

  42. }

  43. return 0;

  44. }

hdu1072http://acm.hdu.edu.cn/showproblem.php?pid=1702

#include <stdio.h>
#include <stack>
#include <queue>
#include <string.h>
using namespace std;
int main()
{
char s[],op[]; int t,num,n; scanf("%d",&t); while(t--) { scanf("%d%s",&n,s); if(s[]=='F') { queue<int> q; while(n--) { scanf("%s",op); if(op[]=='I') { scanf("%d",&num); q.push(num); } else { if(q.empty()) puts("None"); else { printf("%d\n",q.front()); q.pop(); } } } } else { stack<int> s; while(n--) { scanf("%s",op); if(op[]=='I') { scanf("%d",&num); s.push(num); } else { if(s.empty()) puts("None"); else { printf("%d\n",s.top()); s.pop(); } } } } } }

hdu 栈题1022&1702的更多相关文章

  1. 教你用python写:HDU刷题神器

    声明:本文以学习为目的,请不要影响他人正常判题 HDU刷题神器,早已被前辈们做出来了,不过没有见过用python写的.大一的时候见识了学长写这个,当时还是一脸懵逼,只知道这玩意儿好屌-.时隔一年,决定 ...

  2. 转载:hdu 动态规划题集

    1.Robberies 连接 :http://acm.hdu.edu.cn/showproblem.php?pid=2955     背包;第一次做的时候把概率当做背包(放大100000倍化为整数): ...

  3. 动态规划之HDU水题

    做水题的感觉真好系列 HDU 2084 数塔 1: 12: 1 23: 1 2 34: 1 2 3 45: 1 2 3 4 5 dp[i][j]第i行第j个数取得的最大值dp[i][j] = max( ...

  4. hdu刷题2

    hdu1021 给n,看费波纳列数能否被3整除 算是找规律吧,以后碰到这种题就打打表找找规律吧 #include <stdio.h> int main(void) { int n; whi ...

  5. [POJ&HDU]杂题记录

    POJ2152 树形dp,每次先dfs一遍求出距离再枚举所有点转移即可. #include<iostream> #include<cstdio> #include<cma ...

  6. Train Problem I (HDU 100题纪念)

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

  7. (hdu 简单题 128道)平方和与立方和(求一个区间的立方和和平方和)

    题目: 平方和与立方和 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  8. hdu 刷题记录

    1007 最近点对问题,采用分治法策略搞定 #include<iostream> #include<cmath> #include<algorithm> using ...

  9. 莫比乌斯反演--HDU模板题

    题意:http://acm.hdu.edu.cn/showproblem.php?pid=1695 直接上莫比乌斯模板. #include <bits/stdc++.h> using na ...

随机推荐

  1. 【转】ubuntu64,ndk-r9 编译 ffmpeg 2.1.1的config文件

    #!/bin/bash NDK_ROOT=/home/wjh/fox/android-ndk-r9c/ PREBUILT=${NDK_ROOT}toolchains/arm-linux-android ...

  2. selenium验证码处理

    在爬虫过程中经常遇到验证码,如何处理验证码就显得很重要 现在来说貌似没有完美的解决方案,很多都是通过第三方平台来实现验证码的验证 将获取的验证码的url发送到第三方平台,接收平台返回的验证码,貌似很简 ...

  3. autohotkey --- win10运行不兼容

    在win10下许多脚本运行有问题, 将AutoHotkey.exe设置为兼容模式为win7 同时要设置为以管理员身份运行此程序 这个必须得记录一下.

  4. linux设备驱动归纳总结(四):3.抢占和上下文切换【转】

    本文转载自:http://blog.chinaunix.net/uid-25014876-id-65711.html linux设备驱动归纳总结(四):3.抢占和上下文切换 xxxxxxxxxxxxx ...

  5. scala多个构造函数的定义方法

    直接上代码: package com.test.scalaw.test.demo /** * scala定义多个构造函数, * 另外,Scala中有只有一个主要构造函数,其他都是辅助构造函数.而且需要 ...

  6. 创建sh文件

    创建sh文件 #/bin/bash v_file=$ v_type=$ v_desc=$ touch $v_file echo '#================================== ...

  7. C#:通过Window API接口实现WiFi

    1.获取Mac地址 //WiFi通知回调 private WlanApi.WLAN_NOTIFICATION_CALLBACK _notificationCallback; this._notific ...

  8. raw_input() 与 input()

    这两个均是 python 的内建函数,通过读取控制台的输入与用户实现交互.但他们的功能不尽相同. >>> raw_input_A = raw_input("raw_inpu ...

  9. YTU 2344: 先序遍历二叉树

    原文链接:https://www.dreamwings.cn/ytu2344/2603.html 2344: 先序遍历二叉树 时间限制: 1 Sec  内存限制: 128 MB 提交: 4  解决:  ...

  10. Cookie机制(会话cookie和持久化cookie)在客户端保持HTTP状态信息的方案

    1. Cookie只有一个name和一个value,不同于map;购物车设计的时候需要cookie,获取购物车的cookie id,以便于将物品多次放入购物车: 2.cookie获取了其地址,并且可以 ...