Thursday, December 3, 2015

UVa 11244 - Counting Stars

// UVa 11244 - Counting Stars

#include <string>
#include <iostream>
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;
	while ((cin >> n >> m) && (n || m)) {
		string sky[101];
		int sol = 0;
		getline(cin, sky[0]);
		for (int i = 0; i < n; i++)
			getline(cin, sky[i]);
		for (int i = 0; i < n; i++)
			for (int j = 0; j < m; j++)
				if (sky[i][j] == '*') {
					bool star = true;
					for (int k = 0; k < 8; k++) {
						int a = i + move[k][0];
						int b = j + move[k][1];
						if (a >= 0 && a < n && b >= 0 && b < m && sky[a][b] != '.')
							star = false;
					}
					if (star)
						sol++;
				}
		cout << sol << endl;
	}
	return 0;
}

No comments:

Post a Comment