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 reve at 2005-09-23 09:09:44 on Problem 1886
满目的string,list,iterator,map,stdl algorithm。。。。RE了。。。


#include <iostream>
#include <algorithm>
#include <list>
#include <string>
#include <map>

using namespace std;

struct Book
{
	Book()
	{ }
	Book( const string & _a, const string & _t )
		: author(_a), title(_t)
	{ }

	string author;
	string title;
};

bool operator < ( const Book & b1, const Book & b2 )
{
	return (b1.author < b2.author) || (b1.author == b2.author && b1.title < b2.title);
}

list<Book> store;
list<Book> wait;
map<string, string> Map;

void InputBooks()
{
	int idx;
	Book aBook;
	string line;
	while (true)
	{
		getline( cin, line );
		if (line == "END")
			break;

		idx = line.find( '"', 1 );
		aBook.title = line.substr( 0, idx + 1 );
		aBook.author = line.substr( idx + 5, line.length() - idx - 5 );

		store.push_back( aBook );
		Map[aBook.title] = aBook.author;
	}
}

void MakeOrder()
{
	store.sort();
}

void Request()
{
	Book b1;
	Book b2;

	string op;
	string title;
	list<Book>::iterator itBook;
	list<Book>::iterator itWait;

	while (true)
	{
		cin >>op;
		if (op[0] == 'E')
			break;

		if (op[0] == 'B')
		{
			getchar();
			getline( cin, title );
			for (itBook = store.begin(); itBook != store.end(); ++itBook)
			{
				if (itBook->title == title)
				{
					store.erase( itBook );
					break;
				}
			}
		}
		else if (op[0] == 'R')
		{
			getchar();
			getline( cin, title );
			wait.push_back( Book( Map[title], title ) );
		}
		else
		{
			wait.sort();

			for (itWait = wait.begin(); itWait != wait.end(); ++itWait)
			{
				cout <<itWait->author <<' ' <<store.begin()->author <<endl;
				b1 = *itWait;
				if (store.size() == 0)
				{
					store.push_back( *itWait );
					cout <<"Put " <<itWait->title<<" first" <<endl;
					continue;
				}
				else if (itWait->author < store.begin()->author)
				{
					store.insert( store.begin(), *itWait );
					cout <<"Put " <<itWait->title<<" first" <<endl;
				}
				else
				{
				 for (itBook = store.begin(); itBook != store.end(); ++itBook)
				 {
				 	b2 = *itBook;
				 	if (itWait->author > itBook->author)
				 		break;
				 }
				 cout <<"Put " <<itWait->title <<" after " 
                                            <<itBook->title<<endl;
				 store.insert( itBook, *itWait );
				}
			}
			wait.clear();
		}
	}
	cout <<"END" <<endl;
}

int main()
{
	InputBooks();

	MakeOrder();

	Request();

	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