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

stl 很强大哦

Posted by Hirl at 2010-04-12 15:07:56 on Problem 1028
主要就是string和stack两个
string中的assign()方法用于赋值
stack中,pop()用于弹出,top()返回最顶上的函数,empty()判断是否为空,push()用于压栈。
这里给出我的代码,请多指教^__^
#include<iostream>
#include<string>
#include<stack>
using namespace std;

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

void backOperate(void);
void forwardOperate(void);
void visitOperate(string);

int main()
{
	back.empty();
	forward.empty();
	while(cin>>operate)
	{
		if(operate == "QUIT")
		{
			break;
		}
		else if(operate == "VISIT")
		{
			string s;
			cin>>s;
			visitOperate(s);
		}
		else if(operate == "BACK")
		{
			backOperate();
		}
		else
		{
			forwardOperate();
		}
	}
	return 0;
}

void backOperate(void)
{
	if(back.size())
	{
		forward.push(current);
		current.assign(back.top());
		back.pop();
		cout<<current<<endl;
		return;
	}
	cout<<"Ignored"<<endl;
}

void forwardOperate()
{
	if(forward.size())
	{
		back.push(current);
		current.assign(forward.top());
		forward.pop();
		cout<<current<<endl;
		return;
	}
	cout<<"Ignored"<<endl;
}

void visitOperate(string s)
{
	back.push(current);
	while(!forward.empty())
	{
		forward.pop();
	}
	current.assign(s);
	cout<<current<<endl;
}

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