其他语言

本类阅读TOP10

·基于Solaris 开发环境的整体构思
·使用AutoMake轻松生成Makefile
·BCB数据库图像保存技术
·GNU中的Makefile
·射频芯片nRF401天线设计的分析
·iframe 的自适应高度
·BCB之Socket通信
·软件企业如何实施CMM
·入门系列--OpenGL最简单的入门
·WIN95中日志钩子(JournalRecord Hook)的使用

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
浙大在线评测 1178 Booklet Printing

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

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: [email protected]

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;
}




相关文章

相关软件