字符框
遍历整个字符数组即可,注意范围
#include <cstring>
#include <iostream>
using namespace std;
char map[100][100];
void print(int n, int m)
{
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
cout << map[i][j] << " ";
cout << endl;
}
}
bool check(int x, int y)
{
//ANSIC a-97,f-102,c-99,e-101
int test[26] = {0};
test[map[x][y] - 'a'] = 1;
test[map[x + 1][y] - 'a'] = 1;
test[map[x][y + 1] - 'a'] = 1;
test[map[x + 1][y + 1] - 'a'] = 1;
if (test[0] == 1 && test[2] == 1 && test[4] == 1 && test[5] == 1)
return true;
return false;
}
int main()
{
//输入数据
int n, m;
cin >> n >> m;
memset(map, '0', sizeof map);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> map[i][j];
//print(n, m);
//处理数据
int cnt = 0; //计数
for (int i = 0; i < n - 1; i++)
for (int j = 0; j < m - 1; j++)
{
const char &ch = map[i][j];
if (ch == 'f' || ch == 'a' || ch == 'c' || ch == 'e')
if (check(i, j))
cnt++;
else
continue;
}
//输出数据
cout << cnt << endl;
return 0;
}
京公网安备 11010502036488号