题解 | #扫雷#

扫雷

https://www.nowcoder.com/practice/d5f277427d9a4cd3ae60ea6c276dddfd

通过17组用例

import java.util.Scanner;
public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt() + 2;
        int b = sc.nextInt() + 2;
        String c[][] = new String[a][b];
        int d[][] = new int[a][b];
        for (int i = 1; i < a - 1; i++) {
            String s = sc.next();
            for (int j = 1; j < b - 1; j++) {
                char c1 = s.charAt(j - 1);
                if (String.valueOf(c1).equals("*")) {
                    d[i - 1][j - 1] += 1;
                    d[i][j - 1] += 1;
                    d[i + 1][j - 1] += 1;
                    d[i - 1][j] += 1;
                    d[i + 1][j] += 1;
                    d[i - 1][j + 1] += 1;
                    d[i][j + 1] += 1;
                    d[i + 1][j + 1] += 1;
                    c[i][j] = "*";
                }
            }
        }
        for (int i = 1; i < a - 1; i++) {
            for (int j = 1; j < b - 1; j++) {
                if (c[i][j] != null && c[i][j].equals("*")) {
                    System.out.print(c[i][j]);
                } else {
                    System.out.print(d[i][j]);
                }
            }
            System.out.println();
        }

    }
}

全部评论

相关推荐

10-27 02:29
已编辑
门头沟学院 嵌入式工程师
牛客72783561...:简历不是这么写的,你这两个项目只说了用到了什么技术,却没说取得了什么成果,在我看来这就是你自己做的一个demo,没有价值。你为什么不写你电赛国二的那个项目?
点赞 评论 收藏
分享
11-11 16:40
已编辑
门头沟学院 人工智能
不知道怎么取名字_:这个有点不合理了,相当于已经毕业了,但还是没转正,这不就是白嫖
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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