不是题解 | #扫雷游戏#

扫雷游戏

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

  1. 2021年04月15日17:38:34愚蠢的代码
#include <iostream>
using namespace std;

int a[10010][10010] = {0};

int main() {
    int row, col;
    cin >> row >> col;
    for (int i = 0; i < row; i++) {
        for (int j = 0; j < col; j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < row; i++) {
        for (int j = 0; j < col; j++) {
            int count = 0;
            if (a[i][j] == '*') continue;
            if (a[i - 1][j] == '*') count++;
            else if (a[i + 1][j] == '*') count++;
            else if (a[i][j - 1] == '*') count++;
            else if (a[i][j + 1] == '*') count++;
            else if (a[i + 1][j + 1] == '*') count++;
            else if (a[i - 1][j + 1] == '*') count++;
            else if (a[i + 1][j - 1] == '*') count++;
            else if (a[i - 1][j - 1] == '*') count++;
            a[i][j] = count;
            count = 0;
        }
    }
    for (int i = 0; i < row; i++) {
        for (int j = 0; j < col; j++) {
            cout << a[i][j] << endl;
        }
    }
    return 0;
  1. 2021年04月15日18:06:55
#include <iostream>
using namespace std;

int dx[] = {1, 1, 1, 0, 0, -1, -1, -1};
int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};

const int maxn = 105;
char g[maxn][maxn];
int n, m;

int main() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> g[i][j];
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (g[i][j] != '*') {
                int count = 0;
                for (int k = 0; k < 8; k++) {
                    if (g[i + dx[k]][j + dy[k]] == '*') count++;
                }
                cout << count;
            } else {
                cout << '*';
            }
        }
        cout << endl;  // 行末空格
    }
    return 0;
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 10:56
点赞 评论 收藏
分享
Java抽象带篮子:简历怎么写可以看看我发的帖子,你的第一个是实习经历吗?那怎么写的是你的第一个练手项目呢?简历写的怎么样直接投小厂面试一下就知道了
没有实习经历,还有机会进...
点赞 评论 收藏
分享
06-26 10:08
门头沟学院 C++
北京Golang实习,一个月4700,吃住都不报,公司位置在海淀。请问友友怎么看呢?如果要租房的话有什么建议吗
码农索隆:租房肯定是合租了,剩下的钱,差不多够正常吃饭了,看看能不能学到东西吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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