1. JAVA, Till Fischer

/*
============================================================================
Name : Main.java
Author : Till Fischer
Description : 400 - Unix ls
Accepted : Accepted
Time : 0.520
============================================================================
*/

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Collections;


public class Main {

private final static String dashes = "------------------------------------------------------------\n";

public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
ArrayList<String> filenames;
String tempString, formatString;
int columns, totalRows, width, currentRow, currentColumn, currentIndex, longestName, numNames;

while(reader.ready()) {
if((tempString = reader.readLine()) == null) {
break;
}

filenames = new ArrayList<String>();
longestName = 0;

for(numNames = Integer.parseInt(tempString); numNames > 0; numNames--) {
tempString = reader.readLine();
longestName = tempString.length() > longestName ? tempString.length() : longestName;
filenames.add(tempString);
}
numNames = filenames.size();
Collections.sort(filenames);

//output
writer.append(dashes);
columns = 1;
width = 60 - longestName; //min one column that is longest broad
columns += width / (longestName+2); // how many other columns?
width = longestName+2; //thats the average width
totalRows = filenames.size() / columns; //amount of rows
if(filenames.size() % columns != 0) { //if it doesn't fit we need one more row
totalRows++;
}
formatString = "%-"+width+"s"; // left-justified string width = width

for(currentRow = 0; currentRow < totalRows; currentRow++) { //we go row by row

//first column separate cause formula doesn't apply here
writer.append(String.format(formatString, filenames.get(currentRow)));

for(currentColumn = 1; currentColumn < columns; currentColumn++) {
currentIndex = currentColumn*totalRows + currentRow;
if(!(currentIndex >= numNames)) //care not to exceed bounds
writer.append(String.format(formatString, filenames.get(currentColumn*totalRows + currentRow)));
}
writer.append("\n");
}

}
//always be nice to streams!
reader.close();
writer.flush();
writer.close();
}
}