Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std; typedef long long ll; typedef unsigned long long ull; const int mod = 1e9 + 7;
- #define fi first
- #define se second
- #define pb push_back
- #define mp make_pair
- //#define int ll
- int n, m, idx = 0, cnt;
- char a[202][202];
- bool visited[202][202];
- void dfs(int i, int j)
- {
- if (visited[i][j])
- {
- return;
- }
- if (i == 0 || j == 0 || i > n || j > m)
- {
- return;
- }
- if (a[i][j] != '@')
- {
- return;
- }
- visited[i][j] = 1;
- dfs(i, j + 1);
- dfs(i + 1, j);
- dfs(i - 1, j);
- dfs(i, j - 1);
- dfs(i - 1, j + 1);
- dfs(i + 1, j - 1);
- dfs(i + 1, j + 1);
- dfs(i - 1, j - 1);
- }
- signed main()
- {
- ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
- while (cin >> n >> m)
- {
- if (!n && !m)
- {
- return 0;
- }
- memset(visited, 0, sizeof visited);
- idx++;
- cnt = 0;
- for (int i = 1; i <= n; i++)
- {
- for (int j = 1; j <= m; j++)
- {
- cin >> a[i][j];
- }
- }
- for (int i = 1; i <= n; i++)
- {
- for (int j = 1; j <= m; j++)
- {
- if (!visited[i][j] && a[i][j] == '@')
- {
- dfs(i, j);
- cnt++;
- }
- }
- }
- cout << cnt << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement