-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP637.cpp
46 lines (42 loc) · 979 Bytes
/
P637.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <cstdio>
using namespace std;
void printSheet(int sheet, bool front, int left, int right) {
if(left == 0 && right == 0)
return;
cout << "Sheet " << sheet+1 << ", ";
if(front)
cout << "front: ";
else
cout << "back : ";
if(left == 0)
cout << "Blank";
else
cout << left;
cout << ", ";
if(right == 0)
cout << "Blank";
else
cout << right;
cout << endl;
}
int main() {
int N;
while(true) {
cin >> N;
if(N == 0)
return 0;
cout << "Printing order for " << N << " pages:" << endl;
if(N == 1) {
printSheet(0, true, 0, 1);
continue;
}
int numSheets = (N+3)/4;
int leftStart = 4*numSheets;
for(int sheet = 0; sheet < numSheets; ++sheet) {
// Front:
printSheet(sheet, true, leftStart-2*sheet > N ? 0 : leftStart-2*sheet, 2*sheet+1);
printSheet(sheet, false, 2*sheet+2, leftStart-2*sheet-1 > N ? 0 : leftStart-2*sheet-1);
}
}
}