Photolog

Through the Looking-Glass
2010-10-12: Through the Looking-Glass
My radio speaks is binary!
2010-10-10: My radio speaks is binary!
Gigaminx: (present for my birthday)
2010-09-16: Gigaminx: (present for my birthday)
Trini on bike
2010-09-05: Trini on bike
Valporquero
2010-08-28: Valporquero
My new bike!
2010-08-22: My new bike!
Mario and Ana's wedding
2010-08-13: Mario and Ana's wedding
Canyoning in Guara
2010-08-07: Canyoning in Guara
Trini and Mari in Marbella
2010-08-05: Trini and Mari in Marbella
Trini and Chelo in Tabarca
2010-08-03: Trini and Chelo in Tabarca
Valid XHTML 1.1
Log in
Back to list of problems

Oil Deposits

572.c

/* Oil Deposits */
#include <stdio.h>
#include <stdlib.h>

int m,n;
char grid[102][102];

void
recorre(int i, int j) {
	if (i<0 || i>=m || j<0 || j>=n) {
		return;
	}
	if (grid[i][j]!='@') {
		return;
	}
	grid[i][j]='-';
	recorre(i-1,j-1);
	recorre(i-1,j);
	recorre(i-1,j+1);
	recorre(i,j-1);
	recorre(i,j+1);
	recorre(i+1,j-1);
	recorre(i+1,j);
	recorre(i+1,j+1);
}

void
calc(void) {
	int i,j;
	int num=0;

	for(i=0; i<m; i++) {
		for(j=0; j<n; j++) {
			if (grid[i][j]=='@') {
				num++;
				recorre(i,j);
			}
		}
	}
	printf("%d\n", num);
}

int
main(void) {
	int i,j;

	while(1) {
		scanf("%d %d", &m, &n);
		if (m==0) {
			break;
		}
		for(i=0; i<m; i++) {
			char buf[1024];
			scanf("%s", buf);
			for(j=0; j<n; j++) {
				grid[i][j] = buf[j];
			}
		}
		calc();
	}
	exit(0);
}