1.

/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem #10189 Minesweeper
* Link:
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=13&page=show_problem&problem=1130
*
* @author Mohr
* @author Schirm
* @author Mathauser
* @version 1.0, 06/06/2009
*
* Status : Accepted
* Runtime: 0.424
*/

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main
{
public static void main(String...args) throws Exception
{
BufferedReader reader = new BufferedReader(new
InputStreamReader(System.in));
int rows;
int cols;
int[][] mineField;
String[] size;
char[] line;
int count = 1;

while(true)
{
// Zeilen und Spalten auslesen
size = reader.readLine().split(" ");
rows = Integer.parseInt(size[0]);
cols = Integer.parseInt(size[1]);

if(rows == 0 && cols == 0)
break;

// Array mit Rand voller Nullen erstellen
mineField = new int[rows+2][cols+2];

// Minen im Array speichern
for(int i = 0; i < rows; i++)
{
line = reader.readLine().toCharArray();
for(int j = 0; j < cols; j++)
if(line[j] == '*')
mineField[i+1][j+1] = 1;
}

// Leerzeile zwischen zwei Feldern
if (count > 1)
System.out.println();

System.out.println("Field #"+count+":");
for(int i = 0; i < rows; i++)
{
for(int j = 0; j < cols; j++)
if(mineField[i+1][j+1] == 1)
System.out.print("*");
else
System.out.print(mineField[i+2][j+2]+mineField[i+1][j+2]+mineField[i][j+2]
+mineField[i][j]+mineField[i+1][j]+mineField[i+2][j]
+mineField[i][j+1]+mineField[i+2][j+1]);
System.out.println();
}
count++;
}
}
}




2.

/**
 * ACM
 * UVa Status:  accepted
 * Run Time:    0.010
 * Category:    ad hoc
 * @author Evgeni Pavlidis evgenipavlidis@yahoo.de
 */
#include <iostream>

using namespace std;

#define MAX_SIZE 100
#define MINE '*'
#define FREE '.'

static int n,m;

static char f[MAX_SIZE][MAX_SIZE];

void printField()
{
    for(int row=0; row < n; row++, cout << endl )
        for(int col=0; col < m; col++)
            cout << f[row][col];
}

void calcField()
{
    int x,y;
    for(int row=0; row < n; row++)
        for(int col=0; col < m; col++)
            if(f[row][col] == MINE)
                for(int dr=-1; dr <=1; dr++)
                    for(int dc=-1; dc <=1; dc++)
                    {
                        y = row + dr;
                        x = col + dc;
                        if(x < 0 || x >= m || y < 0 || y >= n)
                            continue;

                        if(f[y][x] != MINE)
                            f[y][x]++;
                    }
}

int main()
{
    int caseNumber = 1;
    char tmp;

    while(true)
    {
        cin >> n;
        cin >> m;
        if(n==0)
            return 0;

        for(int row=0; row < n; row++)
            for(int col=0; col < m; col++)
            {
                cin >> tmp;
                f[row][col] = (tmp == MINE)? MINE : '0';
            }
       
        calcField();


        if(caseNumber > 1)
            cout << endl;
        cout << "Field #" << caseNumber++ << ":" << endl;
        printField();

    }
}