poj 1028

  他就是个栈,栈就随便写了,贴代码

#include <iostream>
#include <stack>
#include <string>
using namespace std;
int main(){
    stack<string> stack1,stack2;            string str,s1,s2;
    str="http://www.acm.org/";              stack1.push(str);
    while(cin>>s1){
        if(s1=="QUIT")                      break;
        if(s1=="VISIT"){
            cin>>s2;   cout<<s2<<endl;        stack1.push(s2);
            while(!stack2.empty())          stack2.pop();
        } else if(s1=="BACK"){
            if(stack1.size()>=2){
            stack2.push(stack1.top());      stack1.pop();
            cout<<stack1.top()<<endl;
            } else                          puts("Ignored");
          } else {
            if(!stack2.empty()){
                cout<<stack2.top()<<endl;
                stack1.push(stack2.top());  stack2.pop();
            } else                           puts("Ignored");
        }
    }
    return 0;
}

poj 1028

时间: 2024-11-04 15:02:21

poj 1028的相关文章

【POJ 1028】模拟浏览器

本题要求模拟浏览器的前进.后退等操作. 用两个栈实现,一个控制前进,一个控制后退. 在前进与后退操作中,从一个栈中弹出栈顶元素,压入另一个栈中. 当打开一个新网页时,将前进栈清空. 代码如下: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <cstdlib> #include

POJ 1028 Web Navigation 题解

考查代码能力的题目.也可以说是算法水题,呵呵. 推荐新手练习代码能力. 要增加难度就使用纯C实现一下stack,那么就有点难度了,可以使用数组模拟环形栈.做多了,我就直接使用STL了. #include <stdio.h> #include <iostream> #include <stack> #include <string> using namespace std; int main() { stack<string> forward; s

poj 1028 Web Navigation 【模拟题】

题目地址:http://poj.org/problem?id=1028 测试样例: Sample Input VISIT http://acm.ashland.edu/ VISIT http://acm.baylor.edu/acmicpc/ BACK BACK BACK FORWARD VISIT http://www.ibm.com/ BACK BACK FORWARD FORWARD FORWARD QUIT Sample Output http://acm.ashland.edu/ ht

poj 1028 Web Navigation(模拟题)

题目链接:http://poj.org/problem?id=1028 Description Standard web browsers contain features to move backward and forward among the pages recently visited. One way to implement these features is to use two stacks to keep track of the pages that can be reac

POJ 1028 Web Navigation

Web Navigation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 30689   Accepted: 13750 Description Standard web browsers contain features to move backward and forward among the pages recently visited. One way to implement these features

POJ 1028 Web Navigation (模拟法)

Web Navigation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 29819   Accepted: 13328 Description Standard web browsers contain features to move backward and forward among the pages recently visited. One way to implement these features

POJ 1028题目描述

Description Standard web browsers contain features to move backward and forward among the pages recently visited. One way to implement these features is to use two stacks to keep track of the pages that can be reached by moving backward and forward.

POJ 1028解答

#include <iostream>#include <cstdio>#include <cmath>#include <stack>#include <string> using namespace std; int main(){ char command[16]; char url[71]; stack<string> forwardStack; stack<string> backStack; string cu

FJUTOJ-周赛2016-12-16

注:fjutoj基本每周都有一次周赛,欢迎大家都来参加! 网址:http://210.34.193.66:8080/vj/index.jsp A题:来源 POJ 2773 题意:给两个数m和k,问第k 个和m 互素的数是多少(从1到无穷大). 思路: 二分 + 容斥 先求出m 的素因子p[],数x 和m 互素就意味着x 不存在p 数组中的任意一个素因子,现在要 求n 下面不存在p[]素因子的数的数量可以转化为,n-存在p[]中任意一个素因子的数的个数(经典题型,用容斥可以求),现在二分(k,IN