top of page

소스 코드 제출

공개·회원 50명

20250627

//#include<stdio.h>

//int ar[1005][1005]={},arr[1005][1005]={},c[10005]={}, n, m,q[10005]={}, top=-1, w=-1;

//void push(int a)

//{

// top++;

// q[top]=a;

//}

//void dfs(int a)

//{

// if (c[a]<1)

// {

// c[a]=1;

// printf("%d ", a);

// }

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

// {

// if (ar[a][i]==1)

// {

// ar[a][i]=0;

// ar[i][a]=0;

// dfs(i);

// }

// }

//}

//void bfs()

//{

// while(top>w)

// {

// for(int i=w+1;i<=top;i++)

// {

// int a=q[i];

// if (c[a]<1)

// {

// c[a]=1;

// printf("%d ", a);

// }

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

// {

// if (arr[a][j]==1 && c[j]==0)

// {

// arr[a][j]=0;

// arr[j][a]=0;

// push(j);

// }

// }

// w++;

// }

// }

//}

//int main()

//{

// int k,i,a,b;

// scanf("%d %d %d", &n, &m, &k);

// for(i=1;i<=m;i++)

// {

// scanf("%d %d", &a, &b);

// arr[a][b]=1;

// arr[b][a]=1;

// ar[a][b]=1;

// ar[b][a]=1;

// }

// dfs(k);

// printf("\n");

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

// {

// c[i]=0;

// }

// push(k);

// bfs();

// return 0;

//}

#include<stdio.h>

int arr[30][30]={},n,cnt=0,a[101]={}, i, j,k;

void f(int y, int x)

{

if (arr[y][x]==-1)

{

a[cnt]++;

arr[y][x]=cnt;

f(y+1, x);

f(y-1, x);

f(y, x+1);

f(y, x-1);

}

}

int main()

{

scanf("%d", &n);

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

{

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

{

scanf("%1d", &k);

if (k)

{

arr[i][j]=-1;

}

}

}

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

{

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

{

if (arr[i][j]==-1)

{

cnt++;

f(i,j);

}

}

}

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

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

{

printf("%d\n", a[i]);

}

// printf("\n\n");

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

// {

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

// {

// printf("%d ", arr[i][j]);

// }

// printf("\n");

// }

return 0;

}

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