zoukankan      html  css  js  c++  java
  • uva 10189 扫雷

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

    代码

    #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;
    }
    作 者: itdef
    欢迎转帖 请保持文本完整并注明出处
    技术博客 http://www.cnblogs.com/itdef/
    B站算法视频题解
    https://space.bilibili.com/18508846
    qq 151435887
    gitee https://gitee.com/def/
    欢迎c c++ 算法爱好者 windows驱动爱好者 服务器程序员沟通交流
    如果觉得不错,欢迎点赞,你的鼓励就是我的动力
    阿里打赏 微信打赏
  • 相关阅读:
    Uipath-Close Application和Close Window区别
    我与某猪同学斗智斗勇的那些事
    可视报表(Project)
    自定义函数(Power Query 之 M 语言)
    报表(Project)
    拆分…Split…(Power Query 之 M 语言)
    参加Mos考试
    主要视图展示(Project)
    听听文档(视频)-Power Pivot
    突出显示(Project)
  • 原文地址:https://www.cnblogs.com/itdef/p/11717721.html
Copyright © 2011-2022 走看看