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 ...
随机推荐
- 第一轮复习Servlet day04
* 数据的传送接收:后台通过request发送:req.setAttribute("emps", list); req.getRequestDispatcher("emp ...
- 使用Mysql ID自增长时 在Mapper的<insert>里添加对应的代码
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long&quo ...
- scala抽象类抽象字段
package com.test.scala.test /** * 抽象类学习,定义abstact关键字 */ abstract class AbstractClass { val id:Int;// ...
- zabbix如何实现微信报警 转载
现实生产环境中,我们通常使用邮件和短信接受zabbix报警信息,但是邮件经常被工作人员搁置在角落中甚至被设置为垃圾邮件被过滤掉.公司的短信接口又太贵,复杂环境中使用短息报警会使运维成本增加很多.微信提 ...
- Spring事务注解@Transactional回滚问题
Spring配置文件,声明事务时,如果rollback-for属性没有指定异常或者默认不写:经测试事务只回滚运行时异常(RuntimeException)和错误(Error). <!-- 配置事 ...
- oracle 数据泵 详解
导出数据 1)按用户导 expdp scott/tiger@orcl schemas=scott dumpfile=expdp.dmp DIRECTORY=dir logfile=expdp.log ...
- Hibernate,JPA注解@OneToOne_JoinColumn
一对一(One-to-one),外键关联 用例代码如下: 数据库DDL语句 1,CAT表 create table CAT ( id CHAR) not null, create_time ), up ...
- textarea 在浏览器中禁用拖动和固定大小
HTML 标签 textarea 在大部分浏览器中只要指定行(rows)和列(cols)属性,就可以规定 textarea 的尺寸,大小就不会改变,不过更好的办法是使用 CSS 的 height 和 ...
- 【转载】PostgreSQL分区表(Table Partitioning)应用
博客地址--点击
- List null
List<String> list = new ArrayList<String>(); 不给list add,list也不为null 所以list判断有没有数据,只能用判断l ...