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

终于AC,我是个C++初学者.觉得代码还有很大问题,特贴上,望各位修改........

Posted by qichao at 2009-08-19 10:17:59 on Problem 1028
Source Code

Problem: 1028  User: qichao 
Memory: 224K  Time: 47MS 
Language: C++  Result: Accepted 

Source Code 
#include<iostream>
#include<stack>
#include<string>
#include<cstring>
using namespace std;

int main()
{
	stack<string> forward,back;
	char *c1="http://www.acm.org/";
	string basic(c1);
	char *c2[4]={"QUIT","VISIT","BACK","FORWARD"};
	string current(c1),order;
	while(cin>>order&&order.compare(c2[0]))
	{
		if(!order.compare(c2[1]))
		{
			back.push(current);
			cin>>current;
			cout<<current<<endl;
			while(!forward.empty())
				forward.pop();
		}
		else if(!order.compare(c2[2]))
		{
			if(current!=basic)
				forward.push(current);
			if(!back.empty())
			{
				current=back.top();
				back.pop();
				cout<<current<<endl;
			}
			else
				cout<<"Ignored"<<endl;
		}
		else if(!order.compare(c2[3]))
		{
			if(!forward.empty())
			{
				back.push(current);
				current=forward.top();
				forward.pop();
				cout<<current<<endl;
			}
			else 
				cout<<"Ignored"<<endl;
		}
	}
	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