1313 Booklet Printing
Time Limit: 1000MS
Memory Limit: 10000K
Total Submissions: 861
Accepted: 451
DescriptionWhen 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.
InputThe 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.
OutputFor 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
Sample Output
SourceMid-Central USA 1998
**************************************************************************************
***************************************************************************************
#include <iostream>
using namespace std;
struct page
{
int pageNum[4];
};
int main()
{
int totalPages,sheets;
page pages[26];
int i,p,ps,temp=0,back=0;
while(1)
{
cin>>totalPages;
if( totalPages==0 ) break;
memset(pages,0,sizeof(pages));
sheets=totalPages/4;
if(totalPages%4!=0) sheets++;
back=temp=ps=0;p=-1;
for(i=1; i<=totalPages; i++)
{
if( i<=sheets*2 )
{
if(i%2==1) p++;
if(temp==0)
pages[p].pageNum[1]=i;
else
pages[p].pageNum[2]=i;
temp = (temp+1)%2;
back=0;
}
else
{
if(back==0) { p++; back=1; }
if( i%2==1 ) p--;
if(temp==0)
pages[p].pageNum[3]=i;
else
pages[p].pageNum[0]=i;
temp = (temp+1)%2;
}
}
cout<<"Printing order for "<<totalPages<<" pages:"<<endl;
for(i=0;i<sheets;i++)
{
if( (pages[i].pageNum[0]==0 && pages[i].pageNum[1]==0) )
continue;
cout<<"Sheet "<<i+1<<", front: ";
if(pages[i].pageNum[0]!=0) cout<<pages[i].pageNum[0]<<", ";
else cout<<"Blank, ";
if(pages[i].pageNum[1]!=0) cout<<pages[i].pageNum[1]<<endl;
else cout<<"Blank"<<endl;
if( pages[i].pageNum[2]==0 && pages[i].pageNum[3]==0 )
continue;
cout<<"Sheet "<<i+1<<", back : ";
if(pages[i].pageNum[2]!=0) cout<<pages[i].pageNum[2]<<", ";
else cout<<"Blank, ";
if(pages[i].pageNum[3]!=0) cout<<pages[i].pageNum[3]<<endl;
else cout<<"Blank"<<endl;
}
}
return 0;
}
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
1
14
4
0
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.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
cocos2d Lua 학습(一)ios에서 루아 함수 호출 및 전참 방법 lua 코드: 출력 결과: lua 호출 C++ 방법: add 함수: lua 코드: 출력 결과: 함수를 호출합니다. 함수를 호출하려면 다음 협의를 따르십시오. 우선, 호출할 함...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.