有时候挺无助的,抄的b站上代码却编译不出来
查看原帖
有时候挺无助的,抄的b站上代码却编译不出来
1181769
kelibzd楼主2024/3/7 22:53
#include<bits/stdc++.h>
using namespace std;
int a[35][35],b[35][35];
int n;
void dfs(int x,int y)
{
    if(x<0||x>n+1||y<0||y>n+1||a[x][y]!=0)
    {
        return;
    }
    a[x][y]=1;
    dfs(x-1,y);
    dfs(x+1,y);
    dfs(x,y-1);
    dfs(x,y+1);
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
          cin>>a[i][j];
          if(a[i][j]==0)
          b[i][j]=0;
          else
          b[i][j]=1
        }
    }
    dfs(0,0);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(a[i][j]==0)
            {
                cout<<2<<" ";
            }
            else
            {
                cout<<b[i][j]<<" ";
            }
        }
        cout<<endl;
    }
     return 0;
}
2024/3/7 22:53
加载中...