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 sdau_085111 at 2010-09-02 23:30:27 on Problem 1028
#include<iostream>
#include<stack>
#include<string>
using namespace std;

int main(){
	stack<string> forward_stack;
	stack<string> backforword_stack;
	string state;
	string address;
	backforword_stack.push("http://www.acm.org/");
	while(1){
		cin>>state;
		int i;
		if(state=="QUIT"){
			return 0;
			}
		else if(state=="VISIT"){
			i=0;
			cin>>address;
			backforword_stack.push(address);
			cout<<address<<endl;
			while(!forward_stack.empty()) forward_stack.pop();
		}
		else if(state=="BACK"){
			if(backforword_stack.size()<=1){
				address="Ignored";
			}
			else{
				if(i==0){
					forward_stack.push(backforword_stack.top());
				}
				i++;
				backforword_stack.pop();
				address=backforword_stack.top();
				forward_stack.push(address);
			}
			cout<<address<<endl;
		}
		else if(state=="FORWARD"){
			i=0;
			if(forward_stack.size()<=1){
				address="Ignored";
			}
			else{
				if(forward_stack.size()==1){
					address=forward_stack.top();
					forward_stack.pop();
				}
				else{
					forward_stack.pop();
					address=forward_stack.top();
				}

				backforword_stack.push(address);
			}
			cout<<address<<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