这题题目大致意思就是找它所有的.能否满足五字格,简单遍历就好,直接上代码
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; const int maxn = 100; char a[maxn][maxn]; int lazy[maxn][maxn]; int main() { int x; cin >> x; memset(lazy, 0, sizeof(lazy)); int ans = 0; for (int i = 0; i < x; i++) { getchar(); for (int j = 0; j < x; j++) { scanf("%c", &a[i][j]); if (a[i][j] == '.') { ans++; lazy[i][j] = 1; } } } int sum = 0; for (int i = 0; i < x; i++) { for (int j = 0; j < x; j++) { if (lazy[i][j] == 0||lazy[i][j]==2)continue; if (lazy[i][j] == 1) { if (lazy[i - 1][j] == 1 && lazy[i + 1][j] == 1 && lazy[i][j - 1] == 1 && lazy[i][j + 1] == 1) { sum += 5; lazy[i][j] = 2; lazy[i - 1][j] = 2; lazy[i + 1][j] = 2; lazy[i][j + 1] = 2; lazy[i][j - 1] = 2; } } } } if (sum == ans) { printf("YES "); } else { printf("NO "); } }