首页 > 其他 > 详细

uva 10189 扫雷

时间:2019-10-22 10:46:42      阅读:80      评论:0      收藏:0      [点我收藏+]

技术分享图片

技术分享图片

简单的输入 判断周围上下左右组合的八个方向的雷 然后输出

代码

#include <iostream>
#include <memory.h>

using namespace std;


int n, m;

const int N = 110;

char mine[N][N];

int addx[8] = { 1,-1,1,-1,1,-1,0,0 };
int addy[8] = { 1,-1,-1,1,0,0,1,-1 };

char GetMineCount(int x, int y)
{
    char ret;

    if (mine[x][y] == *)
        return *;

    int count = 0;
    for (int i = 0; i < 8; i++) {
        int newx = x + addx[i];
        int newy = y + addy[i];

        if (newx >= 0 && newx < n && newy >= 0 && newy < m && mine[newx][newy] == *)
            count++;
    }

    ret = 0 + count;
    return ret;
}

int main()
{
    int idx = 0;
    while (1) {
        cin >> n >> m;
        if (n == 0 || m == 0) return 0;
        memset(mine, 0, N*N);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                cin >> mine[i][j];
            }
        }
        if(idx >0 ) cout << endl;

        cout << "Field #" << ++idx << ":" << endl;

        for (int x = 0; x < n; x++) {
            for (int y = 0; y < m; y++) {
                mine[x][y] = GetMineCount(x, y);
                cout << mine[x][y];
            }
            cout << endl;
        }
    }


    return 0;
}

 

uva 10189 扫雷

原文:https://www.cnblogs.com/itdef/p/11717721.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!