<!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-font-kerning:1.0pt;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:595.3pt 841.9pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:42.55pt; mso-footer-margin:49.6pt; mso-paper-source:0; layout-grid:15.6pt;} div.Section1 {page:Section1;} -->

程序设计大赛 —Booklet Printing

When printing out a document,normally the firstpage is printed first,then the second,them 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 regulat book.For example,a 4-page booklet would print on 1 sheet of page:the front will contain page 4 then page 1,and the back will contain page 2 and page 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 Blank in place of a number.if the front or back of a sheet is entirely blank,do noe generate output for that side of the sheet.Output must be in ascending order by sheet,front first,then back.

My program:

/*************************************************

程序名: Booklet Printing

作者:许文发

时间: 2009-11-24

*************************************************/

#include<iostream.h>

#include<stdio.h>

#include<string.h>

int first=1;   // 第一次输出标志

// 获取所需的总页数

int sheetnum(int pages)

{

int m,n;

int num;

m=pages/4;

n=pages%4;

if(n==0)

num=m;

else

num=m+1;

return num;

}

// 打印处理

void print(int book[],int num,int pages)

{

int pagenum=1;

int i;

for(i=1;i<=num*4;i++)

{

if(i%4==2 || i%4==3 && pagenum<=pages)

book[i-1]=pagenum++;

}

for(i=num*4;i>=0;i--)

{

if((i%4==1 || i%4==0)&& pagenum<=pages)

book[i-1]=pagenum++;

}

}

// 清空文件

void clearfile()

{

FILE *pt;

pt=fopen("output.txt","w");

fclose(pt);

}

// 写文件

void mywrite(int book[],int num,int pages,int first)

{

FILE *pt;

pt=fopen("output.txt","a");

int i;

int fro_back=1;

int firstpage=1;

int pageblank=0;

if(first)

fprintf(pt,"Printing order for %d pages:/n",pages);

else

fprintf(pt,"/nPrinting order for %d pages:/n",pages);

for(i=0;i<num*4;i++)

{

if(book[i]==0 && book[i+1]==0)

{

pageblank=1;

}

else

{

pageblank=0;

}

if(pageblank)

{

}

else

{

if(fro_back==1)

{

fro_back=0;

if(firstpage)

{

fprintf(pt,"Sheet %d, front:",i/4+1);

firstpage=0;

}

else

fprintf(pt,"/nSheet %d, front:",i/4+1);

if(book[i]==0)

fprintf(pt," Blank,");

else

fprintf(pt," %d,",book[i]);

if(0==book[i+1])

fprintf(pt," Blank");

else

fprintf(pt," %d",book[i+1]);

}

else

{

fro_back=1;

fprintf(pt,"/nSheet %d, back:",i/4+1);

if(book[i]==0)

fprintf(pt," Blank,");

else

fprintf(pt," %d,",book[i]);

if(0==book[i+1])

fprintf(pt," Blank");

else

fprintf(pt," %d",book[i+1]);

}

}

i++;

}

}

void main()

{

clearfile();

int pages;

int book[100];

FILE *pt;

if(NULL==(pt=fopen("input.txt","r")))

{

}

else

{

fscanf(pt,"%d",&pages);

while(pages!=0)

{

memset(book,0,100);

print(book,sheetnum(pages),pages);

mywrite(book,sheetnum(pages),pages,first);

first=0;

fscanf(pt,"%d",&pages);

}

fclose(pt);

}

}

Input:

1

2

3

4

5

6

7

8

9

10

14

0

Output:

Printing order for 1 pages:

Sheet 1, front: Blank, 1

Printing order for 2 pages:

Sheet 1, front: Blank, 1

Sheet 1, back: 2, Blank

Printing order for 3 pages:

Sheet 1, front: Blank, 1

Sheet 1, back: 2, 3

Printing order for 4 pages:

Sheet 1, front: 4, 1

Sheet 1, back: 2, 3

Printing order for 5 pages:

Sheet 1, front: Blank, 1

Sheet 1, back: 2, Blank

Sheet 2, front: Blank, 3

Sheet 2, back: 4, 5

Printing order for 6 pages:

Sheet 1, front: Blank, 1

Sheet 1, back: 2, Blank

Sheet 2, front: 6, 3

Sheet 2, back: 4, 5

Printing order for 7 pages:

Sheet 1, front: Blank, 1

Sheet 1, back: 2, 7

Sheet 2, front: 6, 3

Sheet 2, back: 4, 5

Printing order for 8 pages:

Sheet 1, front: 8, 1

Sheet 1, back: 2, 7

Sheet 2, front: 6, 3

Sheet 2, back: 4, 5

Printing order for 9 pages:

Sheet 1, front: Blank, 1

Sheet 1, back: 2, Blank

Sheet 2, front: Blank, 3

Sheet 2, back: 4, 9

Sheet 3, front: 8, 5

Sheet 3, back: 6, 7

Printing order for 10 pages:

Sheet 1, front: Blank, 1

Sheet 1, back: 2, Blank

Sheet 2, front: 10, 3

Sheet 2, back: 4, 9

Sheet 3, front: 8, 5

Sheet 3, back: 6, 7

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

程序设计大赛—Booklet Printing相关推荐

  1. HDU 6114 Chess 【组合数】(2017百度之星程序设计大赛 - 初赛(B))

    Chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  2. hdu6383(2018 “百度之星”程序设计大赛 - 初赛(B))

    p1m2 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Sub ...

  3. hdu6380(2018 “百度之星”程序设计大赛 - 初赛(B))

    degree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total S ...

  4. hdu6375(2018 “百度之星”程序设计大赛 - 初赛(A))

    度度熊学队列 Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total S ...

  5. 2018百度之星程序设计大赛 - 资格赛 hdu6345(找区间最小值)

    子串查询 Time Limit: 3500/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Sub ...

  6. nyoj1237 最大岛屿(河南省第八届acm程序设计大赛)

    题目1237 题目信息 执行结果 本题排行 讨论区 最大岛屿 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描写叙述 神奇的海洋.惊险的探险之路,打捞海底宝藏,激烈的海战,海 ...

  7. NYOJ--1236--挑战密室(第八届河南省程序设计大赛)

    挑战密室 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 R组织的特工Dr. Kong 为了寻找丢失的超体元素,不幸陷入WTO密室.Dr. Kong必须尽快找到解锁密码逃 ...

  8. 2017百度之星程序设计大赛 - 复赛 01,03,05

    Arithmetic of Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  9. 2019 年百度之星·程序设计大赛 - 初赛一 C. HDU 6670 Mindis 离散化+dijkstra

    题目链接 :http://acm.hdu.edu.cn/showproblem.php?pid=6670 Mindis Time Limit: 4000/2000 MS (Java/Others) M ...

最新文章

  1. iOS开发资源(持续更新)
  2. cgminer linux cpu,Ubuntu Kylin中编译运行cgminer挖矿软件
  3. ea 备份码是什么_EA的原始访问是什么,值得吗?
  4. 浅谈“三层结构”原理与用意(转帖)
  5. Referenced file contains errors (http://JAVA.sun.com/xml/ns/j2ee/web-app_2_5.xsd).
  6. Nginx自学手册(六)Nginx+Tomcat实现动静分离
  7. es文件浏览器怎么用_谷歌出品的文件管理APP,比ES文件浏览器更简约
  8. 二进位注册文件_注册表导入时提示导入文件不是注册脚本,只能导入二进位注册文件...
  9. 联想win7旗舰版忘记开机密码--有效处理办法
  10. php微博采集,微博采集方法
  11. 世界人工智能大会开幕,云计算概念股大涨
  12. 湖南科技学院计算机代码,湖南科技学院计算机与信息科学系.doc
  13. 手赚网试玩平台源码 可封装APP 带文章资讯功能 帝国cms7.5内核
  14. JS自动播放视频脚本
  15. 使用searx搭建自己的搜索引擎
  16. 6款程序员常用代码对比工具,你用过几款?
  17. EXCEL技巧——EXCEL如何实现隔行隔列求和
  18. AD中PCB布局与布线的一般原则
  19. terminal设置title
  20. Windows下 mysql定时备份

热门文章

  1. Linux下关机命令的区别 (halt,poweroff,reboot,shutdown,init)
  2. 知乎技术分享:知乎千万级并发的高性能长连接网关技术实践
  3. 教你如何把照片做成视频,可做生日party、企业年会、求婚mv视频
  4. matlab里subsystem作用,matlab中的subsystem是什么,怎么建立?
  5. 信息工程学院的毕业晚会
  6. 【机器学习笔记(十)】之通俗易懂理解到底最大似然估计是什么?
  7. 可视化系列讲解:canvas的动画实现
  8. 大数据时代的商业智能
  9. 【杭研大咖说】温正湖:6年,从不会写SQL到数据库专家
  10. 恼火,打篮球打出髌骨软化了