top of page

소스 코드 제출

공개·회원 81명

20260527

#include <stdio.h>


using namespace std;


int cnt=0;

int n;

int ma[30][30]= {0,};

int manu[30]={0,};

void dfs(int x,int y)

{

if(x<1||x>n||y<1||y>n||ma[x][y]!=1) return;

ma[x][y]=0;


dfs(x,y+1);

manu[cnt]=manu[cnt]+1;

dfs(x,y-1);

manu[cnt]=manu[cnt]+1;

dfs(x+1,y);

manu[cnt]=manu[cnt]+1;

dfs(x-1,y);

manu[cnt]=manu[cnt]+1;

}


int main()

{

int k,j,i;

scanf("%d",&n);

for(i=1; i<=n; i++)

{

for(j=1; j<=n; j++)

{

scanf("%1d",&ma[i][j]);

}

}


for(i=1; i<=n; i++)

{

for(j=1; j<=n; j++)

{

if(ma[i][j]==1)

{

dfs(i,j);

cnt++;

}

}

}


printf("%d\n",cnt);

for(i=1;i<=cnt;i++)

{

printf("%d\n",manu[cnt]);

}

return 0;

}

4회 조회
주소 : 경기도 용인시 광교중앙로 302 블루 스퀘어 602호
연락처 : 031) 216 - 1546 ,     031) 215 - 1546
사업자등록번호 : 465-92-00916
​학원 등록 제 4603호
bottom of page