Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <math.h>
- #include <string.h>
- #pragma warning(disable:4996)
- int n, m;
- char map[114][514] = { 0 };
- void dfs(int x, int y){
- if(map[x][y] == '.')return;
- else{
- map[x][y] = '.';
- int dx, dy;
- for(dx = -1; dx <= 1; dx++){
- for(dy = -1; dy <= 1; dy++){
- if(x + dx >= 0 && x + dx < n && y + dy >= 0 && y + dy < m){
- dfs(x + dx, y + dy);
- }
- }
- }
- }
- }
- int main(){
- #ifdef _DEBUG
- freopen("../../../in.txt", "r", stdin);
- #endif
- int i, j, ans = 0;
- scanf("%d%d", &n, &m);
- for(i = 0; i < n; i++){
- scanf("%s", map[i]);
- }
- for(i = 0; i < n; i++){
- for(j = 0; j < m; j++){
- if(map[i][j] == 'W'){
- dfs(i, j); ans++;
- }
- }
- }
- printf("%d\n", ans);
- #ifdef _DEBUG
- freopen("CON", "r", stdin);
- system("pause");
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement