周千童


私信TA

用户名:dotcpp0716578

访问量:76

签 名:

等  级
排  名 1830
经  验 2528
参赛次数 0
文章发表 1
年  龄 0
在职情况 学生
学  校 淄博职业学院
专  业

  自我简介:

TA的其他文章

解题思路:奥利给

注意事项:

参考代码:import java.util.Scanner;

public class test {
   public static void main(String[] args) {
     Scanner sc=new Scanner(System.in);
       int  n1 = sc.nextInt();//行数
       int  n2 = sc.nextInt();//列数
       char [][]a=new char[n1][n2];//用来记录输入时的雷区
       int count=0;//记录某位置周围雷的数量
       int hang,lie;//记录这个位置是否存在于雷区中。
       //开始遍历去将数据输入到a数组中
       for (int i = 0; i <n1; i++) {
           char[] chars = sc.next().toCharArray();
           for (int j = 0; j <n2; j++) {
               a[i][j]=chars[j];
           }
       }
       //开始遍历a数组
       for (int i = 0; i <n1; i++) {
           for (int j = 0; j <n2; j++) {
               //如果遍历到的这个位置是?,则去看其周围有几个雷
               if (a[i][j]=='?'){
                   for (int k = -1; k <=1 ; k++) {
                       for (int l = -1; l <=1 ; l++) {
                           hang=i+k;
                           lie=j+l;

                            //判断位置是否正确合理,合理就加雷的数量。
                           if (hang>=0&&hang<n1&&lie>=0&&lie<n2&&a[hang][lie]=='*'){
                               count++;
                           }
                       }
                   }
                   a[i][j]=(char)(count+48);//ASCII值比数字大48
                   count=0;
               }
           }
       }
       //遍历完后输出
       for (char[] chars : a) {
           for (char aChar : chars) {
               System.out.print(aChar);
           }
           System.out.println();
       }
   }
}

 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区