1. Erste Version: C++, Evgeni Pavlidis


/************************************************
Algorithmen und Problemloesungen mit C++,
http://www.algorithmen-und-problemloesungen.de
Copyright @2007 by Doina Logofatu

- Überarbeitet -
Evgeni Pavlidis
Accepted: 0.010

************************************************/
#include <iostream>

using namespace std;

int main(){
short n, i, k, T, nrPages;
while(true)
{
cin >> n;
if(n==0)
return 0;

cout<<"Printing order for "<< n << " pages:\n";

T=n;
while(n%4) n++;

nrPages=n/4;
for(i=1; i<=nrPages; i++)
{
k=2*(i-1);
cout<<"Sheet "<< i <<", front: ";

if(n-k>T)
cout<<"Blank, ";
else
cout<<n-k<< ", ";

cout<<k+1<<endl;

if(k+2>T && n-k-1>T)
continue;

cout<<"Sheet "<< i <<", back : ";

if(k+2>T)
cout<<"Blank, ";
else
cout<<k+2<<", ";

if(n-k-1>T)
cout<<"Blank";
else
cout<<n-k-1;

cout<<endl;
}
}
return 0;
}

2. Zwiete Version, C,


/************************************************
Algorithmen und Problemloesungen mit C++,
http://www.algorithmen-und-problemloesungen.de
Copyright @2007 by Doina Logofatu

- Überarbeitet -
Evgeni Pavlidis
Accepted: 0.000

************************************************/
#include <stdio.h>


int main()
{
int n, i, k, T, nrPages;
while(1)
{
scanf("%d\n",&n);
if(n==0)
return 0;

printf("Printing order for %d pages:\n", n);

T=n;
while(n%4) n++;

nrPages=n/4;

for(i=1; i<=nrPages; i++)
{
k=2*(i-1);
printf("Sheet %d, front: ", i);

if(n-k>T)
printf("Blank, ");
else
printf("%d, ", n-k);

printf("%d\n",k+1);

if(k+2>T && n-k-1>T)
continue;

printf("Sheet %d, back : ", i);

if(k+2>T)
printf("Blank, ");
else
printf("%d, ",k+2);

if(n-k-1>T)
printf("Blank");
else
printf("%d",n-k-1);

printf("\n");
}
}
return 0;
}

3.


/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10
* Problem: 637 Booklet Printing
* Link:http://uva.onlinejudge.org/external/6/637.pdf
*
* @author Siegfried Ippisch
* @author Martin Lambeck
* @version 1.0, 09/06/2010
*
* Status : Accepted
* Runtime: 0.180
*/


import java.util.Scanner;


public class Main {

private static void printSheet(int pages){
int blanks = (4-pages%4)%4;
int f = 1;
int b = pages+blanks;
int p = 1;

System.out.println("Printing order for " + pages + " pages:");
while(f < b){
print(pages,p++, f, b);
f += 2;
b -= 2;
}
}

private static void print(int pages, int page, int li, int re)
{
String b = ((re > pages) ? "Blank" : "" + re);
re--;
String b2 = ((re > pages) ? "Blank" : "" + re);

System.out.printf("Sheet %d, front: %s, %d%n",page,b,li);
li++;
if (li <= pages)
System.out.printf("Sheet %d, back : %d, %s%n",page,li,b2);

}

public static void main(String[] args){
Scanner input = new Scanner(System.in);

int next = input.nextInt();
while(next != 0){
printSheet(next);

next = input.nextInt();
}

}

}