Código:
#include <iostream>
#include <vector>
using namespace std;
int arrf[8] = { 0, -1, -1, -1, 0, 1, 1, 1 };
int arrc[8] = { -1, -1, 0, 1, 1, 1, 0, -1 };
char s [] = "OIE";
int main() {
int n, m;
while (cin >> n >> m) {
int res = 0;
vector<vector<char> > S(n, vector<char>(m));
for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) cin >> S[i][j];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
for (int d = 0; d < 8; ++d) {
bool trobat = true;
for (int h = 0; h < 3 && trobat; ++h) {
int f = i + h*arrf[d], c = j + h*arrc[d];
if (f < 0 || f >= n || c < 0 || c >= m || S[f][c] != s[h])
trobat = false;
}
if (trobat) res++;
}
}
}
cout << res << endl;
}
}
Saludos. Buenas noches