分享
 
 
 

浙大在线评测 1178 Booklet Printing

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

Problem:

When printing out a document, normally the first page is printed first, then the second, then the third, and so on until the end. However, when creating a fold-over booklet, the order of printing must be altered. A fold-over booklet has four pages per sheet, with two on the front and two on the back. When you stack all the sheets in order, then fold the booklet in half, the pages appear in the correct order as in a regular book.

For example, a 4-page booklet would print on 1 sheet of paper: the front will contain page 4 then page 1, and the back will contain page 2 then page 3.

Front Back

------------- -------------

| | | | | |

| 4 | 1 | | 2 | 3 |

| | | | | |

------------- -------------

Your task is to write a program that takes as input the number of pages to be printed, then generates the printing order.

Input:

The input contains one or more test cases, followed by a line containing the number 0 that indicates the end of the file.

Each test case consists of a positive integer n on a line by itself, where n is the number of pages to be printed; n will not exceed 100.

Output:

For each test case, output a report indicating which pages should be printed on each sheet, exactly as shown in the example. If the desired number of pages does not completely fill up a sheet, then print the word Blank in place of a number. If the front or back of a sheet is entirely blank, do not generate output for that side of the sheet.

Output must be in ascending order by sheet, front first, then back.

Sample Input:

1

14

4

0

Sample Output:

Printing order for 1 pages:

Sheet 1, front: Blank, 1

Printing order for 14 pages:

Sheet 1, front: Blank, 1

Sheet 1, back : 2, Blank

Sheet 2, front: 14, 3

Sheet 2, back : 4, 13

Sheet 3, front: 12, 5

Sheet 3, back : 6, 11

Sheet 4, front: 10, 7

Sheet 4, back : 8, 9

Printing order for 4 pages:

Sheet 1, front: 4, 1

Sheet 1, back : 2, 3

Solution:

#include<iostream>

using namespace std;

// 声明:本代码仅供学习之用,请不要作为个人的成绩提交。

// http://blog.csdn.net/mskia

// email: bitrain@hotmail.com

void arrange( int page ) {

int dec=2;

int front = 1, back = page;

int sheet = page / 4;

if ( page%4 ) sheet++;

switch ( page % 4 ) {

case 0 :

cout << "Sheet 1," << " front: " << back-- << ", " << front++ << endl;

cout << "Sheet 1," << " back : " << front++ << ", " << back-- << endl;

break;

case 1 :

if ( sheet == 1 ) {

cout << "Sheet 1," << " front: Blank" << ", " << front++ << endl;

break;

} else {

cout << "Sheet 1," << " front: Blank" << ", " << front++ << endl;

cout << "Sheet 1," << " back : " << front++ << ", Blank" << endl;

cout << "Sheet 2," << " front: Blank" << ", " << front++ << endl;

cout << "Sheet 2," << " back : " << front++ << ", " << back-- << endl;

dec = 3;

break;

}

case 2:

cout << "Sheet 1," << " front: Blank" << ", " << front++ << endl;

cout << "Sheet 1," << " back : " << front++ << ", Blank" << endl;

break;

case 3:

cout << "Sheet 1," << " front: Blank" << ", " << front++ << endl;

cout << "Sheet 1," << " back : " << front++ << ", " << back-- << endl;

break;

default:

cout << "error";

}

for ( int i = dec; i <= sheet; i++ ) {

cout << "Sheet " << i << "," << " front: " << back-- << ", " << front++ << endl;

cout << "Sheet " << i << "," << " back : " << front++ << ", " << back-- << endl;

}

}

int main( void ) {

for( ; ; ) {

int pages;

cin >> pages;

if ( pages == 0 ) break;

cout << "Printing order for " << pages << " pages:" << endl;

arrange( pages );

}

return 0;

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有