1028-WEB Navigation

题意不重要
两点:
这一题一开始想用带空格的字符数组做,后来发现完全没必要(看代码)
第二点 C++中有堆栈的结构,一开始是用数组做的
易错之处:
visit:一个是forward要清空
      一个是先把当前的存进back 再输入新的当前网页
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>

using namespace std;

string str;
stack<string> backward;
stack<string> forward;
string current = "http://www.acm.org/";

int main()
{
    //freopen("data.in", "rb", stdin);
    while(cin >> str) {
        if(str == "QUIT")
            break;
        else if(str == "VISIT") {
            backward.push(current);
            cin >> current;
            cout << current << endl;
            while(!forward.empty())
                forward.pop();
        }
        else if(str == "BACK") {
            if(!backward.empty()) {
                forward.push(current);
                current = backward.top();
                backward.pop();
                cout << current << endl;
            }
            else
                cout << "Ignored" << endl;
        }
        else if(str == "FORWARD") {
            if(!forward.empty()) {
                backward.push(current);
                current = forward.top();
                forward.pop();
                cout << current << endl;
            }
            else
                cout << "Ignored" << endl;
        }
    }
    
    return 0;
}

//////////////////别人的

我的:

# include <iostream># include <cstdio># include <string># include <cmath>using namespace std;int main(){
	string back[101];
	string forward[101];
	string cur="http://www.acm.org/";
	string str;
	int b=0,f=0;
	cin>>str;
	while(str!="QUIT")
	{
		if(str=="VISIT")
		{
			back[b++]=cur;
			cin>>cur;
			f=0;
			cout<<cur<<endl;
		}
		else if(str=="BACK")
		{
			if(b==0)
			{
				cout<<"Ignored"<<endl;
			}
			else
			{
				forward[f++]=cur;
				cur=back[--b];
				cout<<cur<<endl;
			}
		}
		else if(str=="FORWARD")
		{
			if(f==0)
			{
				cout<<"Ignored"<<endl;
			}
			else
			{
				back[b++]=cur;
				cur=forward[--f];
				cout<<cur<<endl;
			}
		}
		cin>>str;
	}
	return 0;}
时间: 2024-10-26 06:22:12

1028-WEB Navigation的相关文章

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

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 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 【模拟题】

题目地址: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

Web Navigation

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.

zoj 1061 Web Navigation

Web Navigation Time Limit: 2 Seconds      Memory Limit: 65536 KB 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

北大ACM题库习题分类与简介(转载)

在百度文库上找到的,不知是哪位大牛整理的,真的很不错! zz题 目分类 Posted by fishhead at 2007-01-13 12:44:58.0 -------------------------------------------------------------------------------- acm.pku.edu.cn 1. 排序 1423, 1694, 1723, 1727, 1763, 1788, 1828, 1838, 1840, 2201, 2376, 23

POJ百道水题列表

以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive

ACM训练方案-POJ题目分类

ACM训练方案-POJ题目分类 博客分类: 算法 ACM online Judge 中国: 浙江大学(ZJU):http://acm.zju.edu.cn/ 北京大学(PKU):http://acm.pku.edu.cn/JudgeOnline/ 杭州电子科技大学(HDU):http://acm.hdu.edu.cn/ 中国科技大学(USTC):http://acm.ustc.edu.cn/ 北京航天航空大学(BUAA)http://acm.buaa.edu.cn/oj/index.php 南京