C++
注意在输入char型数据时,需使用getchar()吸收换行符。
#include <iostream> #include <cmath> #include <algorithm> #include <vector> #include <cstdio> using namespace std; char a[55][55]; int main(){ int n, m; cin >> n >> m; getchar(); for(int i = 0; i < n; ++i){ for(int j = 0; j < m; ++j){ cin >> a[i][j]; } getchar(); } int cnt = 0; for(int i = 0; i + 1 < n; ++i){ for(int j = 0; j + 1 < m; ++j){ if(a[i][j] != 'f' && a[i + 1][j] != 'f' && a[i][j + 1] != 'f' && a[i + 1][j + 1] != 'f') continue; if(a[i][j] != 'a' && a[i + 1][j] != 'a' && a[i][j + 1] != 'a' && a[i + 1][j + 1] != 'a') continue; if(a[i][j] != 'c' && a[i + 1][j] != 'c' && a[i][j + 1] != 'c' && a[i + 1][j + 1] != 'c') continue; if(a[i][j] != 'e' && a[i + 1][j] != 'e' && a[i][j + 1] != 'e' && a[i + 1][j + 1] != 'e') continue; ++cnt; } } cout << cnt; return 0; }