扫雷 C++

扫雷

https://ac.nowcoder.com/acm/problem/22232

#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

char a[105][105], b[105][105];

int main(){
    int n, m;
    cin >> n >> m;
    getchar();
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < m; ++j){
            cin >> a[i][j];
        }
        getchar();
    }
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < m; ++j){
            int cnt = 0;
            if(a[i][j] == '*') b[i][j] = '*';
            else{
                if(i > 0 && j > 0 && a[i - 1][j - 1] == '*') ++cnt;
                if(i > 0 && a[i - 1][j] == '*') ++cnt;
                if(i > 0 && j + 1 < m && a[i - 1][j + 1] == '*') ++cnt;
                if(j > 0 && a[i][j - 1] == '*') ++cnt;
                if(j + 1 < m && a[i][j + 1] == '*') ++cnt;
                if(i + 1 < n && j > 0 && a[i + 1][j - 1] == '*') ++cnt;
                if(i + 1 < n && a[i + 1][j] == '*') ++cnt;
                if(i + 1 < n && j + 1 < m && a[i + 1][j + 1] == '*') ++cnt;
                b[i][j] = cnt + '0';
            }
            cout << b[i][j];
        }   
        cout << endl;
    }
    return 0;
}
全部评论

相关推荐

点赞 评论 收藏
分享
03-12 09:57
软件测试
程序员小白条:1)确定测试,测开的方向,技术栈不能写这么少 2)课程凑数的,不是99,100分没必要写 3)实习经历这块要有突出的不是劳动性质的亮点,自己设计的什么方案,什么自动化?什么提效工具?不是一些边角料,人云亦云的东西,没吸引力 4) 校园经历纯没用 5)尽量少写减分项
听劝,我这个简历该怎么改...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
正在热议
更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务