UVa 230

Summary
A librarian needs to put books back where they should. The library is computerized.

When a borrower takes out a or returns a book, the computer keeps a record of the title. The librarians ask the program for a series of instructions about the order in which we should arrange the returned books.

Explanation
Consider that the library has a list of books sorting by author's name, if the author's names of two books are the same then sort by title. For this our program needs read and sort the books.

The program can understand four principal events: BORROW, RETURN, SHELVE and END.

BORROW: this command indicates that the borrower takes out a book.

RETURN: this command indicates that the borrower returns a book.

SHELVE: this command indicated that we need to sort the returned books for the moment, sorted by author's name, if the author's names are equals then by title, after that we need create the instructions for the librarian.

Input
"The Canterbury Tales" by Chaucer, G. "Algorithms" by Sedgewick, R. "The C Programming Language" by Kernighan, B. and Ritchie, D. END BORROW "Algorithms" BORROW "The C Programming Language" RETURN "Algorithms" RETURN "The C Programming Language" SHELVE END

Output
Put "The C Programming Language" after "The Canterbury Tales" Put "Algorithms" after "The C Programming Language" END