Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
崇拜我吧。。满目的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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator