首页 > 代码库 > LRJ-Example-06-12-Uva572
LRJ-Example-06-12-Uva572
#define _CRT_SECURE_NO_WARNINGS #include <cstdio> #include <cstring> #include <string> #include <istream> #include <iostream> using namespace std; const int maxm = 100; char grid[maxm + 5][maxm + 5]; int visited[maxm + 5][maxm + 5]; int m, n; int ans; bool count(int i, int j) { if (i < 0 || i >= m || j < 0 || j >= n || grid[i][j] == ‘*‘ || visited[i][j]) return false; visited[i][j] = 1; count(i + 1, j); count(i - 1, j); count(i, j + 1); count(i, j - 1); count(i + 1, j + 1); count(i + 1, j - 1); count(i - 1, j + 1); count(i - 1, j - 1); return true; } int main() { while (cin >> m >> n && m > 0) { memset(grid, 0, sizeof(grid)); memset(visited, 0, sizeof(visited)); ans = 0; string line; getline(cin, line); // consume the newline for (int i = 0; i < m; i++) { getline(cin, line); for (int j = 0; j < n; j++) { grid[i][j] = line[j]; } } for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (count(i, j)) ans++; } } cout << ans << endl; } return 0; }
LRJ-Example-06-12-Uva572
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。