为什么不能用string读入数据
查看原帖
为什么不能用string读入数据
114671
xiaoql楼主2024/1/12 21:39

用string数组全RE 改成char 数组存就没问题,求告知为什么

#include<bits/stdc++.h>
using namespace std;
int n,m,ans,b[200][200];
string s[200];
int dx[5]={0,0,1,-1},
	dy[5]={1,-1,0,0};
void dfs(int x,int y){
	b[x][y]=1;
	for(int i=0;i<4;i++){
		int tx=x+dx[i],ty=y+dy[i];
		if(s[tx][ty]!='0'&&tx>=0&&tx<n&&ty>=0&&ty<m&&!b[tx][ty]){
			dfs(tx,ty);
			
		}
	}

}
int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++)
			cin>>s[i];
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(s[i][j]!='0'&&b[i][j]!=1){
				ans++;
				dfs(i,j);
			}
		}
	}
	
	cout<<ans;
	return 0;
} 
2024/1/12 21:39
加载中...