hdu 栈题1022&1702
http://acm.hdu.edu.cn/showproblem.php?pid=1022
http://blog.csdn.net/swm8023/article/details/6902426此处分类题
hdu1022题copy代码
#include<iostream>
#include<stack>
#define max 100
using namespace std;
int main()
{
stack<char>s;
int n,i,j,k,result[max];//n为列车个数, result数组用来表示结果,1表示进栈。0表示出
char str1[max],str2[max];//序列1和序列2
while(cin>>n>>str1>>str2)
{
j=0,i=0,k=1;
s.push(str1[0]);//为防止栈空,压一个进去
result[0]=1;//记录进来了一个。
while(i<n&&j<n)
{
if(s.size()&&s.top()==str2[j])
{//如果栈顶元素与序列2当前的元素相等,则弹栈,序列2集团向后移一位。
j++;
s.pop();
result[k++]=0;
}
else
{//否则从序列1中取当前元素压入栈中。
if(i==n)break;
s.push(str1[++i]);
result[k++]=1;
}
}
if(i==n)//如果I==N表示栈顶元素不等于序列2当前元素,且序列1中元素都已经入过栈,判断不能得到序列2一样的答案。
cout<<"No."<<endl;
else
{//输出进出栈方式
cout<<"Yes."<<endl;
for(i=0; i<k; i++)
if(result[i])
cout<<"in"<<endl;
else
cout<<"out"<<endl;
}
cout<<"FINISH"<<endl;
}
return 0;
}
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的更多相关文章
- 教你用python写:HDU刷题神器
声明:本文以学习为目的,请不要影响他人正常判题 HDU刷题神器,早已被前辈们做出来了,不过没有见过用python写的.大一的时候见识了学长写这个,当时还是一脸懵逼,只知道这玩意儿好屌-.时隔一年,决定 ...
- 转载:hdu 动态规划题集
1.Robberies 连接 :http://acm.hdu.edu.cn/showproblem.php?pid=2955 背包;第一次做的时候把概率当做背包(放大100000倍化为整数): ...
- 动态规划之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( ...
- hdu刷题2
hdu1021 给n,看费波纳列数能否被3整除 算是找规律吧,以后碰到这种题就打打表找找规律吧 #include <stdio.h> int main(void) { int n; whi ...
- [POJ&HDU]杂题记录
POJ2152 树形dp,每次先dfs一遍求出距离再枚举所有点转移即可. #include<iostream> #include<cstdio> #include<cma ...
- Train Problem I (HDU 100题纪念)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- (hdu 简单题 128道)平方和与立方和(求一个区间的立方和和平方和)
题目: 平方和与立方和 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- hdu 刷题记录
1007 最近点对问题,采用分治法策略搞定 #include<iostream> #include<cmath> #include<algorithm> using ...
- 莫比乌斯反演--HDU模板题
题意:http://acm.hdu.edu.cn/showproblem.php?pid=1695 直接上莫比乌斯模板. #include <bits/stdc++.h> using na ...
随机推荐
- python时间处理函数
所有日期.时间的api都在datetime模块内. 1. 日期输出格式化 datetime => string import datetime now = datetime.datetime.n ...
- java中IO流操作的标准异常类
package 加入异常处理的字节流操作; import java.io.FileNotFoundException; import java.io.FileOutputStream; import ...
- [转]微软SerialPort秘籍[SerialPort为什么死锁程序的分析]
既然是秘籍,显然是写一些大家不常找到的,MSDN里遗漏提示大家注意的东西. 用过.net 2.0中,自带SerialPort的人,大多都遇到过.莫名其妙的执行Close的时候会死掉的问题.而Wince ...
- 【jQuery UI 1.8 The User Interface Library for jQuery】.学习笔记.6.Dialog控件
习惯上,我们播放一条简短的信息,或向浏览者询问一个问题,都会用到dialog. 创建一个基本的dialog 使用dialog 选项 形式 启用内置动画 给dialog添加按钮 使用dialog回调函数 ...
- diff 文件比较
测试数据: [xiluhua@vm-xiluhua][~]$ cat msn.txt aaa bbb bbb ccc ccc ddd bbb eee aaa ccc bbb sss [xiluhua@ ...
- VirtualBox启动虚拟机报错0x80004005
Unable to load R3 module C:\Program Files\Oracle\VirtualBox/VBoxDD.DLL (VBoxDD): GetLastError=1790 ( ...
- UVA 12950 : Even Obsession(最短路Dijkstra)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- ECshop中defined('IN_ECS')的实现原理
在PHP中经常看到如下代码 if (!defined('IN_ECS')) { die('Hacking attempt'); } 实现的原因以及原理如下: ecs ...
- Python基础第一篇
一.第一句python代码 1.python执行过程:1.加载内存-词法分析-语法分析-编译-执行 2.创建hello.py文件,输入内容 #!/usr/bin/env python print &q ...
- mini-treeselect 不允许选父节点的写法
html里的控件事件:onbeforenodeselect = beforenodeselect js里: beforenodeselect : function(e){ //禁止选中父节点 ...