Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 别把横纵坐标搞反了（附代码）

Posted by sunny1995 at 2014-12-07 17:27:44 on Problem 1562
```不说了，一下午，说起来都是泪
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char grids[102][102];
int m,n,dy[8]={-1,-1,-1,0,0,1,1,1},dx[8]={-1,0,1,-1,1,-1,0,1};

void dfs(int x,int y)
{
int k,x0,y0;
grids[x][y]='*';
for (k=0;k<=7;k++)
{
x0=x+dx[k];
y0=y+dy[k];
if (x0>=0&&y0>=0&&x0<=n-1&&y0<=m-1&&grids[x0][y0]=='@')
{
dfs(x0,y0);
}
}
}

int main()
{
int i,j,ans[102]={0},num=0;
char v,c;
do{
scanf("%d%d%c",&n,&m,&v);
if (m==0)
break;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
while(c=getchar(),c!='*'&&c!='@');
grids[i][j]=c;
}
}
for (i=0;i<=n;i++)
for (j=0;j<=m;j++)
{
if (grids[i][j]=='@')
{
dfs(i,j);
ans[num]++;
}
}
memset(grids,'*',sizeof(grids));
num++;
}while(1);
for (i=0;i<=num-2;i++)
printf("%d\n",ans[i]);
printf("%d",ans[num-1]);
return 0;
}
```

Followed by: