1.

/**
 * 
 * Problem #11462 - Age Sort - Loesung 1
 * Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=26&page=show_problem&problem=2457

 * 
 * @author Mariya Vlaseva
 * 
 * Methode: Radix sort
 * Status : Accepted
 * Runtime: 3.320
 */
import java.util.Scanner;

public class Main {

private static final int MAX_NUMBERS_OF_PEOPLE = 2000000;
private static final int INPUT_TERMINATION = 0;

/**
* @param args
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
StringBuilder sb = new StringBuilder();

while(sc.hasNext()) {
int numberOfPeople = sc.nextInt();
if(numberOfPeople == INPUT_TERMINATION) {
break;
}
if(checkInput(numberOfPeople)) {
int[] ages = new int[numberOfPeople];
for(int i = 0; i < numberOfPeople; i++) {
ages[i] = sc.nextInt();
}

radixSort(ages);
for(int age : ages) {
sb.append(age + " ");
}
System.out.println(sb.toString().trim());
sb.delete(0, sb.length());
}
}
}

private static boolean checkInput(int size) {
return size > 0 && size <= MAX_NUMBERS_OF_PEOPLE;
}
public static void radixSort(int[] a) {
int     n;                             // Fachnummer
int[]   nPart = new int[2];            // Anzahl der Elemente in den beiden Faechern
int[][] part  = new int[2][a.length];  // die beiden Faecher haben die Groesse des Arrays a

// Schleife ueber alle Bits der Schluessel (bei int: 32 Bit)
for (int i=0; i<32; i++) {
nPart[0] = 0;
nPart[1] = 0;

// Partitionierungsphase: teilt "a" auf die Faecher auf
for (int j=0; j<a.length; j++) {
n = (a[j]>>i)&1;              // ermittelt die Fachnummer: 0 oder 1                   
part[n][nPart[n]++] = a[j];   // kopiert j-tes Element ins richtige Fach
}

// Sammelphase: kopiert die beiden Faecher wieder nach "a" zusammen
System.arraycopy(part[0], 0, a, 0,        nPart[0]);
System.arraycopy(part[1], 0, a, nPart[0], nPart[1]);
}
}
}

2.

/**
 * 
 * Problem #11462 - Age Sort - Loesung 2
 * http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=26&page=show_problem&problem=2457

 * 
 * @author Mariya Vlaseva
 * 
 * Methode: Countingsort
 * Status : Accepted
 * Runtime: 3.784
 */
import java.util.Arrays;
import java.util.Scanner;

public class Main {

private static final int MAX_NUMBERS_OF_PEOPLE = 2000000;
private static final int INPUT_TERMINATION = 0;

/**
* @param args
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
StringBuilder sb = new StringBuilder();

while(sc.hasNext()) {
int numberOfPeople = sc.nextInt();
if(numberOfPeople == INPUT_TERMINATION) {
break;
}
if(checkInput(numberOfPeople)) {
int[] ages = new int[numberOfPeople];
for(int i = 0; i < numberOfPeople; i++) {
ages[i] = sc.nextInt();
}

countingSort(ages);
for(int age : ages) {
sb.append(age + " ");
}
System.out.println(sb.toString().trim());
sb.delete(0, sb.length());
}
}
}

private static boolean checkInput(int size) {
return size > 0 && size <= MAX_NUMBERS_OF_PEOPLE;
}

public static void countingSort(int[] a) {
// find min, max to set range of counts array
   int low = a[0];
   int high = a[0];
   for(int i=0; i<a.length; i++) {
     if (low > a[i])
       low = a[i];
     else if (high < a[i])
       high = a[i];
   }
   
   int[] counts = new int[high - low + 1]; // this will hold all possible values, from low to high
   for (int x : a)
       counts[x - low]++; // - low so the lowest possible value is always 0
 
   int current = 0;
   for (int i = 0; i < counts.length; i++)
   {
       Arrays.fill(a, current, current + counts[i], i + low); // fills counts[i] elements of value i + low in current
       current += counts[i]; // leap forward by counts[i] steps
   }
}
}




3.

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10
* Problem: 11462 Age Sort
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=74&problem=2457&mosmsg=Submission+received+with+ID+8043192
*
* @author Viktoriya Ryabova
* @version 1.0, 06/28/2010
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 1.348
*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb = new StringBuffer();
while(true){
int count = Integer.parseInt(in.readLine());
if (count==0)return;
StringTokenizer t = new StringTokenizer(in.readLine());

int [] input = new int [count];
for (int i = 0; i<count; i++){
input[i]= Integer.parseInt(t.nextToken());
}
int [] result = countingSort(input);

sb.append(result[0]);
for(int i=1; i<count; i++){
sb.append(" "+ result [i]);
}

System.out.println(sb);
sb.delete(0, sb.length());
}

}

public static int[] countingSort(int[] numbers) {
// Maximum der Zahlen berechnen
int max = numbers[0];
for (int i = 1; i < numbers.length; i++) {
// wenn es größeres als das aktuelle gibt, ist das nun das neue größte
if (numbers[i] > max)
max = numbers[i];
}

// temporäres Array erzeugen mit: Länge = Maximum des Zahlenarrays + die "0"
int[] sortedNumbers = new int[max+1];

// Indizes des Zahlen-Arrays durchgehen
for (int i = 0; i < numbers.length; i++) {
// wir zählen, wie oft jede Zahl aus numbers vorkommt und
// speichern diese Anzahl in sortedNumbers[] bei Index number[i]
sortedNumbers[numbers[i]]++;
}

// insertPosition steht für die Schreib-Position im Ausgabe-Array
int insertPosition = 0;

// Indizes von sortedNumbers[] durchgehen, um zu sehen, wie oft jede Zahl vorkommt
for (int i = 0; i <= max; i++) {
// Anzahl von i durchgehen, um gleiche Zahlen hintereinander einzutragen
for (int j = 0; j < sortedNumbers[i]; j++) {
// das Zahlen-Array wird jetzt sortiert neu geschrieben für jedes
// Auftreten von i
numbers[insertPosition] = i;
insertPosition++;
}
}
return numbers;
}

}