求助大佬们,莫名奇妙的错,本地一点事都没有
查看原帖
求助大佬们,莫名奇妙的错,本地一点事都没有
369897
放学后茶会楼主2020/11/23 22:06
#include<bits/stdc++.h>
using namespace std;
bool ma[500][500];
int ans,z,dx[4]={1 , -1 , 0 , 0},dy[4]={0 , 0 , -1 , 1};
int n;
queue<int> xx;
queue<int> yy;
void bfs(int x,int y){
	xx.push(x);
	yy.push(y);
	while(!xx.empty() && !yy.empty()){
		int qx = xx.front() , qy = yy.front();
		xx.pop();
		yy.pop();
		for(int i = 0 ; i < 4 ; i++){
			int nx = qx + dx[i],ny = qy +dy[i];
			if(ma[nx][ny] && nx > 0 && nx <= n && ny > 0 && ny <= z){
				xx.push(nx);
				yy.push(ny);
				ma[nx][ny] = 0;
			}
		}
	}
}
int main(){
	
	cin>>n;
	getchar();
	for(int i = 1 ; i <= n ; i++){
		int k = 0;
		char a;
		while((a = getchar()) != '\n'){
			if(a == ' ' || a == '*')ma[i][++k] = 0;
			else if(a >= 'a' && a <= 'z')ma[i][++k] = 1;
		}
		z = max(z , k);
	}
/*	for(int i = 1 ; i <= n ; i++){
		for(int j = 1 ; j <= z ; j++){
			cout<<ma[i][j];
		}
		cout<<endl;
	}*/
	for(int i = 1 ; i <= n ; i++){
		for(int j = 1 ; j <= z ; j++){
			if(ma[i][j]){
				ma[i][j] = 0;
				bfs(i , j);
				ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}
2020/11/23 22:06
加载中...