I mean your borrowers of books--those mutilators of collections, spoilers of the symmetry of shelves, and creators of odd volumes.
--Charles Lamb, Essays of Elia (1823) 'The Two Races of Men'
First, the stock of the library will be listed, one book per line, in no particular order. Initially, they are all on the shelves. No two books have the same title. The format of each line will be:
"title" by author
The end of the stock listing will be marked by a line containing only the word:
END
Following the stock list will be a series of records of books borrowed and returned, and requests from librarians for assistance in restocking the shelves. Each record will appear on a single line, in one of the following formats:
BORROW "title"
RETURN "title"
SHELVE
The list will be terminated by a line containing only the word:
END
Each time the SHELVE command appears, your program should output a series of instructions for the librarian, one per line, in the format:
Put "title1" after "title2"
or, for the special case of the book being the first in the collection:
Put "title" first
After the set of instructions for each SHELVE, output a line containing only the word:
END
Assumptions & Limitations
A title is at most 80 characters long.
An author is at most 80 characters long.
A title will not contain the double quote (") character.
"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
Put "The C Programming Language" after "The Canterbury Tales" Put "Algorithms" after "The C Programming Language" END