1. 

/**
 * Angewandte Mathematik, SS09, IFB 2C
 * ACM Problem #445 Marvelous Mazes
 * Link: http://icpcres.ecs.baylor.edu/onlinejudge/external/4/445.pdf
 *
 * @author Mohr
 * @author Schirm
 * @author Mathauser
 * @version 1.0, 04/08/2009
 *
 * Status : Accepted
 * Runtime: 0.160
 */
 
 
import java.io.*;

 
public class Main
{
 
    public static void main(String...args)    throws IOException
    {
        
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String output = "";
        while(true)        // zeile für zeile
        {
            String line = reader.readLine();
            
            if(line == null)
                 break;
            
            int count = 0;
            for(int i =0; i< line.length(); i++)    {
                char chr = line.charAt(i);
                
                if(Character.isDigit(chr))
                    count += Integer.parseInt(Character.toString(chr));
                
                else {
                    if(chr == 'b')
                        chr = ' ';
                    for(int j = 0; j < count; j++)
                        output += chr;
                    count = 0;
                }
                if(chr == '!')
                    output += "\n";
            }
            System.out.println(output);
            output = "";
        }
        
        
    }
}

2.

/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem #445 (Marvelous Mazes)
* http://icpcres.ecs.baylor.edu/onlinejudge/index.php?option=com_onlinejudge&Itemid=8&category=6&page=show_problem&problem=386
*
* @author Christian Posselt
* @author Jonathan Schubert
* @version 1.0, 04/09/2009
*
* Status : Accepted
* Runtime: 0.100
*/

import java.io.*;

class Main {

public static void main(String[] args) throws IOException
{
//Set up needed variables
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
StringBuilder maze = new StringBuilder();
String line;

try
{
while(true)
{
//read in line by line
line = reader.readLine();

if(line==null)
break;

if (!line.isEmpty())
for(int i=0;i<line.length()-1;)
{

int amount = 0;
char character = line.charAt(i);

//add new line if necessary
if(character == '!')
{
maze.append("\n");
i++;
character = line.charAt(i);
}

//count the amount of characters to be printed
while(character >= '0' && character <= '9')
{
amount += line.charAt(i) - '0';
i++;
character = line.charAt(i);
}

//decide whether a character or a space must be placed
if(character == 'b')
for(int j=1;j<=amount;j++)
maze.append(" ");

else
for(int j=1;j<=amount;j++)
maze.append(character);

i++;

}

maze.append("\n");

}
}
finally
{
System.out.print(maze.toString());
}

}
}