Untitled
raw download clone
C
views 12
,
size 1181 b
11691
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

char line;
int visited[1005][1005], ponds[1005][1005];
int n, m;
int count, ans;

int dfs(int now_x, int now_y)
{
    if (ponds[now_x][now_y] == '.') return 0;
    else if (visited[now_x][now_y]) return 0;
    else {
        visited[now_x][now_y] = 1;
        if (ponds[now_x][now_y + 1] == '~') dfs(now_x, now_y + 1);
        if (ponds[now_x][now_y - 1] == '~') dfs(now_x, now_y - 1);
        if (ponds[now_x + 1][now_y] == '~') dfs(now_x + 1, now_y);
        if (ponds[now_x - 1][now_y] == '~') dfs(now_x - 1, now_y);
        count++;
    }
    return count;
}

int main(void)
{
    scanf("%d%d", &m, &n);
    scanf("%c", &line);
    for (int i = 0;i < m;i++) {
        for (int j = 0;j < n;j++) {
            scanf("%c", &ponds[i][j]);
            visited[i][j] = 0;
        }
        scanf("%c", &line);
    }

    for (int i = 0;i < m;i++) {
        for (int j = 0;j < n;j++) {
            if (visited[i][j] == 0) {
                count = 0;
                if (dfs(i, j)) ans++;

            }
        }
    }
    
	printf("%d\n" , ans);


    return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.