杭电 1241 Oil Deposits(不该表字符数组值的写法)

#include <stdio.h>
#define MAXM 110
#define MAXN 110
char mat[MAXM][MAXN];
int vis[MAXM][MAXN];

int n, m;
void dfs(int i, int j)
{
    int dx, dy;
    int nx, ny;
    vis[i][j] = 1;
    mat[i][j] = '*';
    for( dx = -1; dx <= 1; dx++ )
        for( dy = -1; dy <= 1; dy++ )
        {
            nx = i + dx;
            ny = j + dy;

            if( nx>=0 && nx<m && ny>=0 && ny<n && (!vis[nx][ny]) && (mat[nx][ny]=='@'))
            {
                dfs(nx,ny);
            }
        }
}
int main()
{
    int i, j, res;
    while( (scanf("%d%d", &m ,&n) != EOF) && m )
    {
        getchar();
        for( i = 0; i < m; i++ )
        {
            for( j = 0; j < n; j++ )
                scanf("%c",&mat[i][j]);
            getchar();
        }
        for( i = 0; i < m; i++ )
            for( j = 0; j < n; j++ )
                vis[i][j] = 0;
        /*for( i = 0; i < m; i++ )
        {
            for( j = 0; j < n; j++ )
                printf( "%c ", mat[i][j] );
            printf("\n");
        }*/
        res = 0;
        for( i = 0; i < m; i++ )
            for( j = 0; j < n; j++ ) 
                if( mat[i][j] == '@' )
                {
                    //printf("%d %d\n",i, j);
                    dfs(i,j);
                    res++;
                }
        printf( "%d\n", res );
    }
    return 0;
}
View Code

 

posted @ 2013-08-05 16:16  翼展zjz  阅读(169)  评论(0编辑  收藏  举报