congpho115
Giới thiệu
include <iostream>
bool check(char arr[1001][1001],int i,int j);
int main(){
int n,m;
std::cin>>n>>m;
char arr[1001][1001];
for(int i=0; i<n; i++){
for(int j=0; j\<m; j++){
std::cin>>arr[i][j];
}
}
int rooms=0;
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
if(arr[i][j]=='.'){
if(check(arr, i, j)){
rooms++;
}
arr[i][j] = '1';
}
}
}
std::cout << rooms;
}
bool check(char arr[1001][1001],int i,int j){
if(arr[i-1][j]=='1'||arr[i+1][j]=='1'||arr[i][j-1]=='1'||arr[i][j+1]=='1'||arr[i-1][j-1]=='1'||arr[i+1][j+1]=='1'||arr[i-1][j+1]=='1'||arr[i+1][j-1]=='1'){
return false;
}else return true;
}