1. 
/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS11
* @author Beinhofer Christian
* @version 1.0
*
* Flooding-Algorithmus
* 8975782 785 Grid Colouring Accepted C++ 0.088 2011-06-22 07:42:35
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=9&page=show_problem&problem=726
*/

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <vector>

char map[31][81];

void flood(int r, int c, char color)
{
int col, row;

map[r][c] = color;

for(int ac = -1; ac < 2; ac++)
{
col = c + ac;
for(int ar = (ac == 0 ? -1 : 0); ar < 2; ar+=2)
{
row = r + ar;
if(map[row][col] == ' ')
{
flood(row, col, color);
}
}
}
}

int main()
{
int value;
int c = 0, r = 0;

char zonechar = -1;

bool startendline = false;

std::vector<int> x;
std::vector<int> y;

while((value = getchar()) != EOF)
{
if(value == '\r') continue;
if(value == '\n')
{
map[r][c] = '\0';
r++;
c = 0;
}
else
{
// Get the zonechar
if((zonechar == -1) && (value != ' '))
zonechar = value;

if((value != zonechar) && (value != ' ') && (c != 0))
{
x.push_back(r);
y.push_back(c);
}

map[r][c++] = value;
}


if((c == 1) && (value == '_'))
{
while((value = getchar()) != EOF)
{
if(value == '\n')
{
map[r][c] = '\0';

for(unsigned int i = 0; i < x.size(); i++)
{
flood(x[i], y[i], map[x[i]][y[i]]);
}
x.clear();
y.clear();

for(int i = 0; i <= r; i++)
{
printf("%s\n", map[i]);
}

r = 0;
c = 0;

break;
}
else map[r][c++] = value;
}
}
}

return 0;
}