• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            技術,瞎侃,健康,休閑……

            mahu@cppblog 人類的全部才能無非是時間和耐心的混合物
            posts - 11, comments - 13, trackbacks - 0, articles - 12
              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

            Booklet Printing

            Posted on 2006-06-16 23:26 mahudu@cppblog 閱讀(431) 評論(0)  編輯 收藏 引用 所屬分類: C/C++
            ???

            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 file 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;
            #define?PAGES?100

            typedef?
            struct?side{????
            ????
            int?left,right;
            }
            side;

            typedef?
            struct?sheet{
            ????side?front;
            ????side?back;????
            }
            sheet;

            int?numSides;
            sheet?sheets[PAGES];

            void?PrintPages(int?numSides){
            ????
            int?numSidesNew;????
            ????
            int?add,pages;
            ????add?
            =?numSides%4;
            ????
            if(add?!=?0){
            ????????numSidesNew?
            =?numSides?+?4?-?add;????//?增加后的總面數,numSides為實際的總面數
            ????}

            ????
            else
            ????????numSidesNew?
            =?numSides;
            ????pages?
            =?numSidesNew?/?4;????//?總紙張數
            ????for(int?i?=?0;?i?<?pages;?i++){
            ????????sheets[i].front.left?
            =?numSidesNew?-?2*i;
            ????????
            if(sheets[i].front.left?>?numSides){
            ????????????sheets[i].front.left?
            =?0;????//?表明應為blank
            ????????}

            ????????sheets[i].front.right?
            =?2*i+1;
            ????????
            if(sheets[i].front.right?>?numSides){
            ????????????sheets[i].front.right?
            =?0;????//?表明應為blank
            ????????}

            ????????sheets[i].back.left?
            =?2*(i+1);
            ????????
            if(sheets[i].back.left?>?numSides){
            ????????????sheets[i].back.left?
            =?0;????//?表明應為blank
            ????????}

            ????????sheets[i].back.right?
            =?numSidesNew?-?2*i?-?1;
            ????????
            if(sheets[i].back.right?>?numSides){
            ????????????sheets[i].back.right?
            =?0;
            ????????}

            ????}


            ????cout?
            <<?"Printing?order?for?"?<<?numSides?<<?"?pages:"?<<?endl;
            ????
            for(int?j?=?0;?j?<?pages;?j++){
            ????????
            if(sheets[j].front.left?||?sheets[j].front.right){
            ????????????cout?
            <<?"Sheet?"?<<?j+1?<<",?front:?";
            ????????????
            if(sheets[j].front.left)
            ????????????????cout?
            <<?sheets[j].front.left?<<?",";
            ????????????
            else
            ????????????????cout?
            <<?"Blank,";
            ????????????cout?
            <<?"?";
            ????????????
            if(sheets[j].front.right)
            ????????????????cout?
            <<?sheets[j].front.right;
            ????????????
            else
            ????????????????cout?
            <<?"Blank,";
            ????????????cout?
            <<?endl;
            ????????}

            ????????
            if(sheets[j].back.left?||?sheets[j].back.right){
            ????????????cout?
            <<?"Sheet?"?<<?j+1?<<",?back?:?";
            ????????????
            if(sheets[j].back.left)
            ????????????????cout?
            <<?sheets[j].back.left?<<?",";
            ????????????
            else
            ????????????????cout?
            <<?"Blank,";
            ????????????cout?
            <<?"?";
            ????????????
            if(sheets[j].back.right)
            ????????????????cout?
            <<?sheets[j].back.right;
            ????????????
            else
            ????????????????cout?
            <<?"Blank";
            ????????????cout?
            <<?endl;
            ????????}


            ????}

            }



            int?main()
            {
            ????
            int?numSides;
            ????
            while(cin?>>?numSides){
            ????????
            if(numSides?==?0){
            ????????????
            break;
            ????????}

            ????????PrintPages(numSides);
            ????}

            ????
            return?0;
            }

            欧美伊香蕉久久综合类网站| 无码国内精品久久人妻蜜桃| 72种姿势欧美久久久久大黄蕉| 久久久久四虎国产精品| 日本精品久久久中文字幕| 日本福利片国产午夜久久| 午夜精品久久久久久影视777| 99精品久久精品一区二区| 四虎国产永久免费久久| 欧美激情一区二区久久久| 久久99精品国产自在现线小黄鸭| 久久精品国产亚洲Aⅴ蜜臀色欲| 亚洲日韩中文无码久久| 国产成人精品久久亚洲高清不卡| 久久亚洲AV无码精品色午夜麻豆| 久久亚洲精品视频| 亚洲精品国产美女久久久| 久久亚洲欧洲国产综合| 国产精品九九九久久九九| 狠狠色丁香婷婷久久综合五月| 久久本道伊人久久| 久久丫精品国产亚洲av不卡 | 久久久久久人妻无码| 国产精品伊人久久伊人电影| 久久狠狠高潮亚洲精品| 久久综合色老色| 久久国产欧美日韩精品| 久久久精品国产Sm最大网站| 久久青草国产精品一区| 亚洲国产欧美国产综合久久| 亚洲精品高清一二区久久| 久久国产成人| 99久久国产免费福利| 26uuu久久五月天| 天天综合久久久网| 国产成人精品久久亚洲高清不卡 | 国产成人精品久久一区二区三区av| 囯产精品久久久久久久久蜜桃| 无码国内精品久久综合88| 97精品依人久久久大香线蕉97| 2020久久精品亚洲热综合一本|