编程介的小学生 2017-02-12 16:45 采纳率: 20.5%
浏览 832
已采纳

Booklet Printing

Description

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

  • 写回答

2条回答 默认 最新

  • devmiao 2017-02-13 18:21
    关注

    #include
    int s[500][4];
    int main()
    {
    int P,i;
    while (scanf("%d",&P)!=EOF)
    {
    if (P==0) return 0;
    int N=(P-1)/4+1;
    int M=4*N;
    int l=1,r=M;
    for (i=1;i<=N;i++)
    {
    s[i][0]=r--;
    s[i][1]=l++;
    s[i][2]=l++;
    s[i][3]=r--;
    }
    printf("Printing order for %d pages:\n",P);
    for (i=1;i<=N;i++)
    {
    if (!(s[i][0]>P && s[i][1]>P))
    {
    printf("Sheet %d, front:",i);
    if (s[i][0]>P) printf(" Blank, ");
    else printf(" %d, ",s[i][0]);
    if (s[i][1]>P) printf("Blank\n");
    else printf("%d\n",s[i][1]);
    }
    if (!(s[i][2]>P && s[i][3]>P))
    {
    printf("Sheet %d, back :",i);
    if (s[i][2]>P) printf(" Blank, ");
    else printf(" %d, ",s[i][2]);
    if (s[i][3]>P) printf("Blank\n");
    else printf("%d\n",s[i][3]);
    }
    }
    }
    return 0;
    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算