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 KatrineYang at 2016-06-08 14:24:59 on Problem 1028
//============================================================================
// Name        : main1028.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

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

class node{
public:
	string url;
	node* next;
	node* prev;
	node(string u){
		url = u;
		next = NULL;
		prev = NULL;
	}
	~node(){
		if(next != NULL) delete next;
		//delete this;
	}
};



int main() {
	string start = "http://www.acm.org/";
	node* head = new node(start);
	node* cur = head;
	string cmd;
	while(getline(cin, cmd)){
		stringstream ss(cmd);
		string dz;
		ss >> dz;
		if(dz == "QUIT") return 0;
		else if(dz == "VISIT"){
			string vURL;
			ss >> vURL;
			node* nN = new node(vURL);
			nN->prev = cur;
			delete cur->next;
			cur->next = nN;
			cur = nN;
			cout << vURL << endl;
		}
		else if(dz == "BACK"){
			if(cur->prev == NULL){
				cout << "Ignored" << endl;
			}
			else{
				cur = cur->prev;
				cout << cur->url << endl;
			}
		}
		else if(dz == "FORWARD"){
			if(cur->next == NULL){
				cout << "Ignored" << endl;
			}
			else{
				cur = cur->next;
				cout << cur->url << endl;
			}
		}
		else continue;
	}
	//cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
	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