经调试,发现有的地方就是染不到。。。
查看原帖
经调试,发现有的地方就是染不到。。。
322705
Mr_Ender楼主2020/6/5 22:24
#include<iostream>
using namespace std;
char map[105][105];
int n,m,num=0;
struct node{
	int x;
	int y;
};
void work(int x,int y){
	struct node que[10005],v;
	int fro=1,beh=2;
   	while(fro<beh){
    	que[1].x=x;
    	que[1].y=y;
    	v=que[fro];
    	v.x++;
    	if(map[v.x][v.y]=='W'&&v.x<=n){
    		map[v.x][v.y]='.';
    		que[beh]=v;
    		beh++;
    	}
    	v.x--;
    	if(map[v.x][v.y]=='W'&&v.x>=1){
    		map[v.x][v.y]='.';
    		que[beh]=v;
    		beh++;
    	}
    	v.y++;
    	if(map[v.x][v.y]=='W'&&v.y<=m){
    		map[v.x][v.y]='.';
    		que[beh]=v;
    		beh++;
    	}
    	v.y--;
    	if(map[v.x][v.y]=='W'&&v.y>=1){
    		map[v.x][v.y]='.';
     		que[beh]=v;
    		beh++;
    	}
    	v.x++;
    	v.y--;
	    if(map[v.x][v.y]=='W'&&v.x<=n&&v.y>=1){
	    	map[v.x][v.y]='.';
	    	que[beh]=v;
	        beh++;
	    }
	    v.x--;
	    v.y++;
	    if(map[v.x][v.y]=='W'&&v.x>=1&&v.y<=m){
	    	map[v.x][v.y]='.';
		    que[beh]=v;
		    beh++;
	    }
	    v.x++;
	    v.y++;
	    if(map[v.x][v.y]=='W'&&v.x<=n&&v.y<=m){
		    map[v.x][v.y]='.';
		    que[beh]=v;
		    beh++;
	    }
	    v.x--;
	    v.y--;
	    if(map[v.x][v.y]=='W'&&v.x>=1&&v.y>=1){
	    	map[v.x][v.y]='.';
	    	que[beh]=v;
	    	beh++;
    	}
	    fro++;
    }
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>map[i][j];
		} 
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(map[i][j]=='W'){
				num++;
				work(i,j);
			}
		}
	}
	cout<<num;
	return 0;
} 
2020/6/5 22:24
加载中...