Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

其实用一个数组就可以了。。。

Posted by et1239063237 at 2012-07-09 00:51:09 on Problem 1028
#include<iostream>
#include<string>

using namespace std;

int main()
{
	//设置数组初始状态
	string str[100]={""};
	str[0]="http://www.acm.org/";
	int counter=0;
	int max=0;

	//读取指令
	string mystr;
	cin>>mystr;
	
	//读取 QUIT 指令直接结束程序
	//否则进入语法分析
	while(mystr[0]!='Q')
	{
		//读取 VISIT 指令则访问网址
		if(mystr[0]=='V')
		{
			//cout<<"info:VISIT"<<endl;

			counter++;
			max=counter;
			cin>>mystr;
		    str[counter]=mystr;
			cout<<str[counter]<<endl;

			cin>>mystr;
			continue;
		}

		//读取 BACK 看是否在堆栈底部
		//不在底部则执行 BACK 动作
		if(mystr[0]=='B' && counter!=0)
		{
			//cout<<"info:BACK"<<endl;

			counter--;
			cout<<str[counter]<<endl;

			cin>>mystr;
			continue;
		}

		//在底部则拒绝执行 BACK 指令
		if(mystr[0]=='B' && counter==0)
		{
			//cout<<"info:BACK"<<endl;

			cout<<"Ignored"<<endl;

			cin>>mystr;
			continue;
		}

		//读取 FORWARD 看是否在堆栈曾经的最前部
		//不是则执行 FORWARD 指令
		if(mystr[0]=='F' && max>=counter+1)
		{
			//cout<<"info:FORWARD"<<endl;

			counter++;
			cout<<str[counter]<<endl;

			cin>>mystr;
			continue;
		}

		//是则拒绝执行 FORWARD 指令
		if(mystr[0]=='F' && max<counter+1)
		{
			//cout<<"info:FORWARD"<<endl;

			cout<<"Ignored"<<endl;

			cin>>mystr;
			continue;
		}
		
	}

	return(0);
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator