Library Codes
Time limit1sMemory limit128 MB
For each book, print horizontal if f times label length plus 2 is at most the book width, otherwise print vertical.
- Level
Easy1 of 10
- Topics
- Implementation
- Solved
- No attempts yet
Problem
A library is relabelling its books using the Dewey Decimal classification. Whenever it fits, a label is printed horizontally; if the text is wider than the book, it is printed vertically instead.
The label uses a fixed-pitch (monospaced) font, so every character occupies exactly mm of width. For readability, a 1 mm gap must be left both before and after the printed text. A label can therefore be printed horizontally only when
where is the number of characters in the label text and is the width of the book in mm. Otherwise the label must be printed vertically.
Given each library's character width, each book's width, and each label's text, decide for every book whether its label is printed horizontally or vertically.
Input
The input describes several libraries.
Each library is given as follows:
- The first line contains the library's name (letters only, no spaces, at most 20 characters) and a single integer (), the width in mm of one character, separated by a space.
- The next line contains a single integer , the number of books for this library.
- Each of the following lines describes one book: an integer (), the width of the book in mm, and the label text (between 3 and 6 characters, no spaces), separated by a space.
The input ends with a line containing # 0 (a #, a space, then a 0); this line is not a library and must not be processed.
Output
For each library, first print the library's name followed by a space and the word Library on its own line. Then, for each book in the order given, print a line Book k horizontal or Book k vertical, where is the book's position in the library's list starting from 1, and the word is horizontal if the label fits horizontally or vertical otherwise.