码迷,mamicode.com
首页 > 其他好文 > 详细

LRJ-Example-06-12-Uva572

时间:2017-08-04 20:42:16      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:max   eof   str   ret   name   ted   warning   cstring   ems   

#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

标签:max   eof   str   ret   name   ted   warning   cstring   ems   

原文地址:http://www.cnblogs.com/patrickzhou/p/7286735.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!