m0_65749592 2024-06-12 10:31 采纳率: 35.5%
浏览 0

getMatrixList里面装的就是很多数据 打印出来就是不管多少行都在这一个数据里

public void updateMatrix(List bomb, List<List> getMatrixList) {
} 需求: 1.每个炸弹数据包括行、列和值信息,根据这些信息在矩阵列表中更新对应位置的值。如果值为1000,将该位置的值设置为5;如果值在10到25之间,将该位置的值设置为6;如果值在50到100之间,将该位置的值设置为7
2.假设现在打印出来的bomb=[0_1_3, 0_2_8, 0_1_9, 1_1_18,1_2_50,1_2_10,2_1_3,3_15_20],getMatrixList==
139 4 4 137 101 137
139 137 139 101 127 139
131 137 109 107 101 127
139 127 103 137 137 139
139 139 109 107 139 109
103 4 137 137 101 139
137 4 4 101 101 131
107 137 109 107 127 137
107 137 103 137 101 127
131 127 109 107 137 109
137 139 109 103 113 137
103 139 4 139 101 139
107 4 109 101 101 131
107 4 103 107 127 127
131 127 109 107 101 109
3.我会按照bomb的位置去getMatrixList里面找到然后重新跟新getMatrixList的值,bom里面是下标存储的 所以0_1_3的0是代表第一行第2列然后值是3,但是需要注意的是:getMatrixList现在有15行 相当于有三个矩阵,因为每5行相当于一个5行6列的矩阵
4.getMatrixList里面没有分子列表 就打印出来就是这样的 ,所以当 3_15_20,这个15其实是需要找到getMatrixList的倒数第五行的位置的我的3_15是只有列处理过翻倍,行是没有,我现在代码就是改怎么实现呢 中文注释帮我改一下
5.其实就是把getMatrixList划分成5行算一个矩阵,假设划分第一个数列按照下标列是012345, 那到下一个矩阵5行列就是678910,11,再往下就是12,13,14,15,16,所以3_15_20就找到15列的然后是第4行,能明白吗 ,

以下是我的代码有问题
//修改甜蜜财富1000经验球的大小中表现

public void updateMatrix(List<String> bomb, List<List<Integer>> getMatrixList) {
        for (String b : bomb) {
            String[] bombInfo = b.split("_");
            int row = Integer.parseInt(bombInfo[0]);  
            int column = Integer.parseInt(bombInfo[1]); 
            int value = Integer.parseInt(bombInfo[2]);
            // 计算实际在getMatrixList中的位置
            int matrixIdx = row / 5;  // 矩阵索引
            int matrixRow = row % 5;  // 矩阵中的行位置
            int actualRow = matrixIdx * 5 + matrixRow;  //实际行位置
            if (value == 1000) {
                getMatrixList.get(actualRow).set(column, 5);
            } else if (value >= 10 && value <= 25) {
                getMatrixList.get(actualRow).set(column, 6);
            } else if (value > 25 && value <= 50) {
                getMatrixList.get(actualRow).set(column, 7);
            }
        }
    }

  • 写回答

2条回答 默认 最新

  • 阿里嘎多学长 2024-06-12 10:38
    关注

    以下内容由CHATGPT及阿里嘎多学长共同生成、有用望采纳:


    根据你的需求和提供的代码,我注意到几个需要修改的地方:

    1. 你的条件判断有一个小错误,在判断炸弹值在50到100之间的条件判断中,应该是value > 50 && value <= 100,而不是value > 25 && value <= 50
    2. 你的代码逻辑基本正确,但是需要添加中文注释来解释代码的逻辑。

    下面是修改后的代码,包括中文注释:

    public void updateMatrix(List<String> bomb, List<List<Integer>> getMatrixList) {
        // 遍历炸弹数据列表
        for (String b : bomb) {
            // 将炸弹数据字符串按"_"分割成数组
            String[] bombInfo = b.split("_");
            // 从数组中获取行索引、列索引和值
            int row = Integer.parseInt(bombInfo[0]);  // 炸弹数据中的行索引
            int column = Integer.parseInt(bombInfo[1]);  // 炸弹数据中的列索引
            int value = Integer.parseInt(bombInfo[2]);  // 炸弹数据中的值
    
            // 计算实际在getMatrixList中的位置
            int matrixIdx = row / 5;  // 计算矩阵索引
            int matrixRow = row % 5;  // 计算在矩阵中的行位置
            int actualRow = matrixIdx * 5 + matrixRow;  // 计算实际行位置
    
            // 根据炸弹的值更新getMatrixList中对应位置的值
            if (value == 1000) {
                // 如果炸弹值为1000,更新矩阵对应位置的值为5
                getMatrixList.get(actualRow).set(column, 5);
            } else if (value >= 10 && value <= 25) {
                // 如果炸弹值在10到25之间,更新矩阵对应位置的值为6
                getMatrixList.get(actualRow).set(column, 6);
            } else if (value > 50 && value <= 100) {
                // 如果炸弹值在50到100之间,更新矩阵对应位置的值为7
                getMatrixList.get(actualRow).set(column, 7);
            }
        }
    }
    

    这段代码应该能够满足你的需求,正确地根据炸弹数据来更新getMatrixList中的值。如果你需要更多的参考资料,你可以查看Java的官方文档,特别是关于ListArrayList的使用方法:

    这些文档会提供更多关于如何在Java中使用列表和数组的详细信息。

    评论 编辑记录

报告相同问题?

问题事件

  • 创建了问题 6月12日

悬赏问题

  • ¥15 PVE8.2.7无法成功使用a5000的vGPU,什么原因
  • ¥15 is not in the mmseg::model registry。报错,模型注册表找不到自定义模块。
  • ¥15 安装quartus II18.1时弹出此error,怎么解决?
  • ¥15 keil官网下载psn序列号在哪
  • ¥15 想用adb命令做一个通话软件,播放录音
  • ¥30 Pytorch深度学习服务器跑不通问题解决?
  • ¥15 部分客户订单定位有误的问题
  • ¥15 如何在maya程序中利用python编写领子和褶裥的模型的方法
  • ¥15 Bug traq 数据包 大概什么价
  • ¥15 在anaconda上pytorch和paddle paddle下载报错