1. JAVA, Gunnar Hage

/**
* ACM programming Contest WS 08/09 "785 - Grid Colouring"
* Verdict: Wrong answer
*
* Gunnar Hage, gunnarhage@gmx.de
* AP5(IFB5A) Okt. 2008
*
* Aufgabe: http://icpcres.ecs.baylor.edu/onlinejudge/index.php?option=com_onlinejudge&Itemid=8&category=9&page=show_problem&problem=726
*
*
XXXXXXXXXXXXXXXXXXXX
X X X
X # # XXXXXXXX / X
X X X
XXXXXXXXXXXXXXXXXXXX
_____________________________

XXXXXXXXXXXX XXXXXX
X # XXX XXX X X
X XX X X X X
X X X XXXXXXX XXXXXXX
X XX X
X X XXXX XXXXXXXX
XX XXXX X X / X
X X X / X
XXXXXXXXXXXXX XXXXXXXX
_____________________________

SSSSSSSSSSSSSSSSSSSS
S S S
S + SSSSSSSS f S
S S S
SSSSSSSSSSSSSSSSSSSS
_____________________________

XXXXXXXXXXXX XXXXXX
X k XXX XXX X X
X XX X X m X X
X X X XXXXXXX XXXXXXX
X XX X
X X XXXX XXXXXXXX
XX XXXX X X s X
X X X s X
XXXXXXXXXXXXX XXXXXXXX
_____________________________


*/
//package p785_Grid_Colouring;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;

public class Main {

public static void main(String... args){
BufferedWriter br = new BufferedWriter(new OutputStreamWriter(System.out));
boolean read = false;
try {
while(System.in.available() > 1 || !read)
{
read = true;
colorAGrid(br);
br.write("\n");
br.flush();
}
} catch (IOException e) {
e.printStackTrace();
}
}

static void colorAGrid(BufferedWriter br) throws IOException{
char[][] grid = new char[310][];
int c=0;
char grenzen = ' ';
char expandchar = '0';
String line = ReadLn(255);
if(line != null)
grenzen = line.trim().charAt(0);
while(line != null)
{
grid[c++] = line.toCharArray();
line = ReadLn(255);
}
for(int y=1; y<grid.length-1; y++){
if(grid[y]!=null){
for(int x=1; x<grid[y].length-2; x++){
if(grid[y][x] != ' ' && grid[y][x] != grenzen && grid[y][x] != '\r' && grid[y][x] != '_'){
expandchar = grid[y][x];
if(grid[y][x+1] == ' ') // Zeichne rechts der Position
grid[y][x+1] = expandchar;
if(grid[y+1][x] == ' ') // Zeichne unterhalb der Position
grid[y+1][x] = expandchar;
// Wenn er oberhalb zeichnet,
if(grid[y-1][x] == ' '){
grid[y-1][x] = expandchar;
//auch noch links gucken und dann
if(grid[y][x-1] == ' ')
grid[y][x-1] = expandchar;
y--;// eine Zeile weiter oben
x--;// in der gleichen Spalte weitersuchen.
}
// Wenn er nicht oberhalb aber links Zeichnet
else if(grid[y][x-1] == ' '){
grid[y][x-1] = expandchar;
x-=2; // In der gleichen Zeile ein Feld links gucken.
}
}
}
}
}
for(char[] y: grid){
if(y!=null)
for(char x: y)
br.append(x);
}
}

static String ReadLn (int maxLg) // utility function to read from stdin
{
byte lin[] = new byte [maxLg];
int lg = 0, car = -1;
try
{
while (lg < maxLg)
{
car = System.in.read();
if ((car < 0) || (car == '\n')) break;
lin [lg++] += car;
}
}
catch (IOException e)
{
return (null);
}
if (car < 0 || lg < 2) return (null); // eof
return (new String (lin, 0, lg));
}
}