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 ...
随机推荐
- 有趣的insert死锁
昨天看到一个很有意思的死锁,拿来记录下: 环境:deadlock on 事务隔离级别: read commited 表结构: root::>show create table lingluo\G ...
- webservice引用spring的bean
<jaxws:endpoint address="/test/webservice" implementor="#testBean" /> 这行代码 ...
- maven在windows环境下加载settings.xml文件
今天发现maven在windows环境下加载的settings.xml文件是c:下的,就算修改conf下的settings.xml里的<localRepository>给他明确指向也没用.
- GCD 多线程同步
@property (strong, nonatomic) dispatch_queue_t barrierQueue; _barrieQueue = dispatch_queue_create(&q ...
- HLS视频直播
HTTP Live Streaming (HLS) 苹果官方对于视频直播服务提出了 HLS 解决方案,该方案主要适用范围在于: 使用 iPhone .iPod touch. iPad 以及 Apple ...
- pipe row的用法, Oracle split 函数写法.
为了让 PL/SQL 函数返回数据的多个行,必须通过返回一个 REF CURSOR 或一个数据集合来完成.REF CURSOR 的这种情况局限于可以从查询中选择的数据,而整个集合在可以返回前,必须进行 ...
- ACM题目————滑雪
Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道 ...
- 简单LRU算法实现缓存
最简单的LRU算法实现,就是利用jdk的LinkedHashMap,覆写其中的removeEldestEntry(Map.Entry)方法即可,如下所示: java 代码 import java.ut ...
- LA 3704 Cellular Automaton
题意概述: 等价地,本题可以转化为下面的问题: 考虑$n \times n$的$0-1$矩阵$A$,在第$i$行上第$[-d+i, d+i]$(模$n$意义下)列对应的元素为$1$,其余为$0$.求$ ...
- combox绑定后添加自定义列
DataTable dt = shUBll.FindAllByWhere(""); DataRow dr = dt.NewRow(); dr["SUID"] = ...