| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:字符数组没初始化。。wa了好几次。。谨记In Reply To:字符数组没初始化。。wa了好几次。。谨记 Posted by:dad_mom at 2010-08-10 14:17:48 一样啊~唉~
#include <stdio.h>
#include <string.h>
char map[21][21];
int dir[8][2] = { {0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {-1, -1}, {1, -1}, {-1, 1} };
int c;
int sx, sy;
int m, n;
int jud( int x, int y )
{
int sum = 4;
for( int i=0; i<4; i++ )
{
int xx = x+dir[i][0];
int yy = y+dir[i][1];
if( xx < 0 || xx >= n || yy <0 || yy >= n )
{
continue;
}
if( map[xx][yy] == 'X' || map[xx][yy] == 'Y' )
{
sum--;
}
}
//printf("%d..\n", sum);
return sum;
}
void dfs( int x, int y )
{
if( x<0 || y<0 || x>=m || y >=n )
{
return ;
}
if( map[x][y] == 'X' )
{
c += jud( x, y );
map[x][y] = 'Y';
for( int i=0; i<8; i++ )
{
int xx = x + dir[i][0];
int yy = y + dir[i][1];
if( map[xx][yy] == 'X' )
{
dfs( xx, yy );
}
}
}
else
{
return ;
}
}
int main()
{
while(scanf("%d %d %d %d%*c", &m, &n, &sx, &sy), m+n+sx+sy)
{
memset( map, 0, sizeof(map) );//错在这了啊~~~~~
sx--;
sy--;
for( int i=0; i<m; i++ )
{
scanf("%s", map[i]);
}
c = 0;
dfs( sx, sy );
printf("%d\n", c);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator