📄 pku1562.cpp
字号:
#include <stdio.h>
char lake[105][105];
int N, M;
int dis[8][2] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}};
void cls(int x, int y)
{
int i, nextx, nexty;
lake[x][y] = 'c';
for (i = 0; i < 8; i++)
{
nextx = x + dis[i][0];
nexty = y + dis[i][1];
if (nextx >= 0 && nextx < N && nexty >= 0 && nexty < M && lake[nextx][nexty] == '@')
{
cls(nextx, nexty);
}
}
}
int main()
{
int i, j, count = 0;
while (scanf("%d%d", &N, &M) != -1)
{
count = 0;
if (M == 0 && N == 0)
{
break;
}
for (i = 0; i < N; i++)
{
scanf("%s", lake[i]);
}
for (i = 0; i < N; i++)
{
for (j = 0; j < M; j++)
{
if (lake[i][j] == '@')
{
count++;
cls(i, j);
}
}
}
printf("%d\n", count);
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -