【poj解题】1028
stack的应用
#include<iostream>
#include<stack>
#include<stdio.h>
#include<stdlib.h>
#include<string.h> #define MAX 128 using namespace std; stack<char *> back_stack;
stack<char *> forward_stack; int main() {
char raw[MAX];
char * now;
char * s;
now = (char *)malloc(sizeof(char) * 128);
strcpy(now, "http://www.acm.org/");
while(1) {
cin >> raw;
if(raw[0] == 'Q') {
break;
}
if(raw[0] == 'V') {
cin >> raw;
back_stack.push(now);
s = (char *)malloc(sizeof(char) * MAX);
strcpy(s, raw);
now = s;
printf("%s\n", s);
while(!forward_stack.empty()) {
forward_stack.pop();
}
}
else if(raw[0] == 'B') {
if(back_stack.size() == 0) {
printf("Ignored\n");
}
else {
s = back_stack.top();
back_stack.pop();
printf("%s\n", s);
forward_stack.push(now);
now = s;
}
}
else if(raw[0] == 'F') {
if(forward_stack.size() == 0) {
printf("Ignored\n");
}
else {
s = forward_stack.top();
forward_stack.pop();
printf("%s\n", s);
back_stack.push(now);
now = s;
}
}
else {
;
}
}
while(back_stack.size() != 0) {
s = back_stack.top();
free(s);
back_stack.pop();
}
while(forward_stack.size() != 0) {
s = forward_stack.top();
free(s);
forward_stack.pop();
}
return 0;
}
【poj解题】1028的更多相关文章
- POJ解题经验交流
感谢范意凯.陈申奥.庞可.杭业晟.王飞飏.周俊豪.沈逸轩等同学的收集整理. 题号:1003 Hangover求1/2+1/3+...1/n的和,问需多少项的和能超过给定的值 类似于Zerojudg ...
- 【poj解题】3664
简单,两次排序 #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX 500 ...
- 【poj解题】3663
排序, 遍历,需要裁减 #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX ...
- 【poj解题】1308
判断一个图是否是一个树,树满足一下2个条件即可:1. 边树比node数少12. 所有node的入度非0即1 节点数是0的时候,空树,合法树~ 代码如下 #include <stdio.h> ...
- [poj解题]1017
Packets Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 41014 Accepted: 13776 Descrip ...
- 洛谷 P1731 [NOI1999]生日蛋糕 && POJ 1190 生日蛋糕
题目传送门(洛谷) OR 题目传送门(POJ) 解题思路: 一道搜索题,暴力思路比较容易想出来,但是这道题不剪枝肯定会TLE.所以这道题难点在于如何剪枝. 1.如果当前状态答案已经比我们以前某个状态 ...
- poj 1028
http://poj.org/problem?id=1028 题意(水):做一个游览器的历史记录. back:后退到上一个页面,当上一个页面没有时,输出ignored. forward:向前一个页面, ...
- POJ 1003 解题报告
1.问题描述: http://poj.org/problem?id=1003 2.解题思路: 最直观的的想法是看能不能够直接求出一个通项式,然后直接算就好了, 但是这样好水的样子,而且也不知道这个通项 ...
- POJ 1004 解题报告
1.题目描述: http://poj.org/problem?id=1004 2.解题过程 这个题目咋一看很简单,虽然最终要解出来的确也不难,但是还是稍微有些小把戏在里面,其中最大的把戏就是float ...
随机推荐
- ASP.NET获取客户端信息,获取客户端IP等等
山上明月 ASP.NET能知道的东西 获取服务器电脑名: Page.Server.ManchineName 获取用户信息: Page.User 获取客户端电脑名:Page.Request.UserHo ...
- 【转】javascript Object使用Array的方法
原文: http://www.cnblogs.com/idche/archive/2012/03/17/2403894.html Array.prototype.push push向数组尾部添加一项并 ...
- Webkit之资源加载
一.webkit资源分类 webkit中有多种资源,大致分为以下几种: HTML文本 CSS样式文本 - CachedCSSStyleSheet 字体 - CachedFont 图片 - Cached ...
- ActiveX控件在IE中不响应Backspace消息
1.操作输入法需要导入: #include <imm.h> #pragma comment(lib, "imm32") 2.定义变量: //键盘钩子句柄 HHOOK g ...
- THOUGHTS: programming in linux... with third_party open sources... methods
Actually I do not have experiences in programming with open sources/third party libs.. in linux.. I ...
- [转]Android Shape渲染的使用(经典,学习研究不后悔)
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://mzh3344258.blog.51cto.com/1823534/1215749 ...
- java 实例变量和类变量的区别
Example4_10.java public class Example4_10 { public static void main(String args[]) { Lader.下底=100; / ...
- ios 概况了解
iOS的系统架构分为四个层次:( iOS是基于UNIX内核,android是基于Linux内核) 核心操作系统层(Core OS layer).核心服务层(Core Services layer).媒 ...
- andorid 自定义view属性declare-styleable
1. reference:参考某一资源ID. (1)属性定义: <declare-styleable name = "名称"> <attr name = &quo ...
- mysql笔记4之数据操作
1修改数据 插入:insert into stu(id,name,age,addr) values(2,"李四",44,"重庆"); 2修改某一列 updata ...