Booklet Printing
Time limit1sMemory limit128 MB
For each page count, print which page numbers (or Blank) go on each side of every sheet in fold-over booklet order.
- Level
Easy3 of 10
- Topics
- Array, Implementation, Simulation
- Solved
- No attempts yet
Problem
When printing a document, pages are normally printed in order: page 1 first, then page 2, then page 3, and so on until the last page. However, when printing a fold-over booklet, the printing order must be changed.
A fold-over booklet holds four pages on each sheet of paper: two on the front and two on the back. When all sheets are stacked in order and the whole stack is folded in half, the page numbers appear in the correct order, just like in an ordinary book. For example, a 4-page booklet prints on a single sheet: the front holds page 4 then page 1 (left to right), and the back holds page 2 then page 3.
Front Back
------------- -------------
| | | | | |
| 4 | 1 | | 2 | 3 |
| | | | | |
------------- -------------
Given the number of pages to print, write a program that produces the printing order.
Input
The input consists of one or more test cases, followed by a line containing a single 0 that marks the end of the file. Each test case is a single positive integer on its own line, the number of pages to print. does not exceed 100.
Output
For each test case, print a report describing which pages go on each sheet.
First print a line of the form Printing order for n pages: (where n is the number of pages). Then, in ascending order of sheet number, print each sheet's front first and its back second.
A front line has the form Sheet k, front: a, b, and a back line has the form Sheet k, back : a, b (note the single space after back that aligns it with front). Here k is the sheet number, and a and b are the page numbers printed at those positions.
If the number of pages does not completely fill a sheet, print the word Blank instead of a number in each empty position. If the entire front or the entire back of a sheet is blank, do not print a line for that side.
Print one blank line between the outputs of consecutive test cases.