POJ 1028 Web Navigator

【题意简述】:题目的大概意思,就是模仿浏览器的功能,实现访问(VISITE)URL,前进(FORWORD),后退(BACK)

这些功能!

【思路】:可以模拟栈的用法!后进先出,实现这一功能。

实现功能,详见代码!!

/*0ms,164KB*/

#include<iostream>
#include<string>
using namespace std;

string stack[101];

int main()
{
    int top;
    int Max1;
    int n;
	string op;
	
//	cin>>n;
	//while(n--){
	Max1 = 0;	
	top = 0;	
	stack[top] = "http://www.acm.org/";	
	while (cin >> op, op[0] != 'Q')
	{
		
	
		if (op[0] == 'V')
		{
			string web;
			cin >> web;
			stack[++top] = web;
			cout << web << endl;
			Max1 = top;
		}
		else if (op[0] == 'B')
		{
			if (top != 0)
				cout << stack[--top] << endl;
			else
                cout << "Ignored" << endl;
		}
		else//'F'
		{
			if (top < Max1)
				cout << stack[++top] << endl;
			else
                cout << "Ignored" << endl;
		}
	//	}
		//cout<<endl;
	}

	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值