Thursday, June 18, 2015

UVa 10189 - Minesweeper

// UVa 10189 - Minesweeper

#include <iostream>
#include <string>
using namespace std;

int move[8][2] = { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, { 1, 1 } };

int main() {
	int n, m, t = 0;
	while ((cin >> n >> m) && (n || m)) {
		t++;
		string line;
		getline(cin, line);
		string in[100];
		for (int i = 0; i < n; i++)
			getline(cin, in[i]);
		for (int i = 0; i < n; i++)
			for (int j = 0; j < m; j++)
				if (in[i][j] != '*') {
					in[i][j] = '0';
					for (int k = 0; k < 8; k++) {
						int a = i + move[k][0];
						int b = j + move[k][1];
						if (0 <= a && a < n && 0 <= b && b < m && in[a][b] == '*')
							in[i][j]++;
					}
				}
		if (t > 1)
			cout << endl;
		cout << "Field #" << t << ":" << endl;
		for (int i = 0; i < n; i++)
			cout << in[i] << endl;
	}
	return 0;
}

No comments:

Post a Comment