12分求助(c++)
查看原帖
12分求助(c++)
1280343
a111111111111楼主2024/5/16 10:01

只有12分

#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false); cin.tie(0); int n,z=0,lz=0; cin>>n;
	vector<vector<int>> a(n,vector<int>(n)); char xx;
	for(vector<int> &X:a)
	{
	    for(int &x:X) cin>>xx,x=(xx!='#'),lz+=(xx=='#');
	}
	for(int x=0;x<n;x++)
	{
	    for(int y=0;y<n;y++)
	    {
	        if(a[x][y]!=0) continue;
	        if(a[x-1][y]==1 or a[x][y-1]==1 or a[x+1][y]==1 or a[x][y+1]==1)
	        {
	            z++;
	            a[x][y]=2;
	        }
	    }
	}
	cout<<lz-z;
	return 0;
}
2024/5/16 10:01
加载中...