思路
遍历字符数组,考虑以当前遍历字符为左上元素的2*2矩阵是否符合规则即可
#include <bits/stdc++.h>
using namespace std;
int n,m,cot,res = 0;
char car[52][52];
bool jgface(int x,int y){ //利用质因数分解的唯一性
cot = 1;
for(int i = x;i <= x+1;i++)
for(int j = y;j <= y+1;j++){
if(car[i][j] == 'f') cot *= 2;
if(car[i][j] == 'a') cot *= 3;
if(car[i][j] == 'c') cot *= 5;
if(car[i][j] == 'e') cot *= 7;
}
if(cot == 210) return true;
else return false;
}
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(0);
cin>>n>>m;
for(int i = 1;i <= n;i++)
for(int j = 1;j <= m;j++)
cin>>car[i][j];
for(int i = 1;i <= n-1;i++) //判断以i,j为左上顶点的2*2矩形是否满足要求
for(int j = 1;j <= m-1;j++) //遍历至边界-1即停,省去边界判断
if(jgface(i,j)) res++;
cout<<res;
return 0;
}