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 ...
随机推荐
- linux下串口控制
/* 本程序符合GPL条约 * Beneboy 2003-5-16 */ #include <stdio.h> // printf #include < ...
- V4L2读取摄像头程序流程【转】
本文转载自:https://my.oschina.net/u/1024767/blog/210801 v4l2 操作实际上就是 open() 设备, close() 设备,以及中间过程的 ioctl( ...
- wghd的git代码仓库分支管理说明【转】
英文原文:http://www.nvie.com/posts/a-successful-git-branching-model/ 原文作者:Vincent Driessen 本文经Linux大棚博主总 ...
- 【jQuery UI 1.8 The User Interface Library for jQuery】.学习笔记.4.Tabs控件
之前,我们已经介绍了 jQuery UI 库,CSS 框架.下面,我们将学习这些有增强可视化效果,高度可配置的用户交互组件. Tab 的特性是,点击 tab 后,会高亮该 tab,并显示他的关联con ...
- 给NIOS II CPU添加一颗澎湃的心——sysclk的使用
给NIOS II CPU添加一颗澎湃的心——系统时钟的使用 本实验介绍如何在Qsys中添加一个定时器作为NIOS II的心跳定时器,并在NIOS II中软件编程使用该定时器. 将上一个实验watchd ...
- 工作上的C/C++相关
LKSnapShot.h的line127某个类的声明中有: public: typedef TClient<LPeer, ACE_DEV_Connector> _TClient; 这种情况 ...
- 使用Jil序列化JSON提升Asp.net web api 性能
JSON序列化无疑是Asp.net web api 里面性能提升最重要的一环. 在Asp.net web api 里面我们可以插入自定义的MediaTypeFormatter(媒体格式化器), 说白了 ...
- CalParcess.php.
<?php require_once "OperSerVice.class.php"; //接受三个数 //isset if(!isset($_REQUEST['NUM1'] ...
- php之属性重载和方法重载
<?php /** * * @authors Your Name (you@example.org) * @date 2016-06-13 20:40:19 * @version $Id$ */ ...
- Google Analytics Premium VS Adobe Analytics
在很久以前的互联网年代,Google收购了一家名为Urchin的公司,进而演化诞生了Google Analytics.当Goochin(Google / Urchin)首次亮相时,它被所有人称为“新的 ...