3 条题解
-
2
#include <bits/stdc++.h> using namespace std; int w = 1,h = 1,a,b,sun = 0; char z[25][25];
void afd(int x,int y){ sun++; z[x][y] = '/';
if(z[x+1][y] == '.'){ afd(x+1,y); } if(z[x-1][y] == '.'){ afd(x-1,y); } if(z[x][y+1] == '.'){ afd(x,y+1); } if(z[x][y-1] == '.'){ afd(x,y-1); }
}
int main(){ while(cin >> h >> w&&(w!=0||h!=0)){ sun = 0; for(int i = 1;i<=20;i++){ for(int j = 1;j<=20;j++){ z[i][j] = ' '; } } for(int i = 1;i<=w;i++){ for(int j = 1;j<=h;j++){ cin >> z[i][j]; if(z[i][j] == '@'){ a = i; b = j;
} } } afd(a,b); cout << sun << endl; }
}
信息
- ID
- 216
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 8
- 标签
- 递交数
- 62
- 已通过
- 10
- 上传者