Skip to content

Instantly share code, notes, and snippets.

@fredbr

fredbr/costa.cpp Secret

Created May 22, 2018 22:23
Show Gist options
  • Save fredbr/453dac9fef526f578b4978dd39d65fbc to your computer and use it in GitHub Desktop.
Save fredbr/453dac9fef526f578b4978dd39d65fbc to your computer and use it in GitHub Desktop.
//solucao de Frederico Bulhoes
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
char v[maxn][maxn];
int main()
{
int m, n;
cin >> m >> n;
for (int i = 0; i <= m+1; i++) {
v[i][0] = '.';
v[i][n+1] = '.';
}
for (int i = 0; i <= n+1; i++) {
v[0][i] = '.';
v[m+1][i] = '.';
}
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
cin >> v[i][j];
}
}
int total = 0;
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
if (v[i][j] == '#') {
if (v[i-1][j] == '.' or v[i+1][j] == '.' or v[i][j-1] == '.' or v[i][j+1] == '.') total++;
}
}
}
cout << total << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment