题解 | #矩阵乘法#
矩阵乘法
https://www.nowcoder.com/practice/ebe941260f8c4210aa8c17e99cbc663b
HJ69 矩阵乘法
基于JavaScript Node编译器
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); const inputArr = []; rl.on("line", function (line) { inputArr.push(line.split(" ")); }).on("close", function(){ fun(inputArr); }); function fun(inputArr){ let x = parseInt(inputArr[0][0]); let y = parseInt(inputArr[1][0]); let z = parseInt(inputArr[2][0]); let arr1 = []; let arr2 = []; let arr3 = []; for(let i = 0; i < x; i++){ arr1[i] = inputArr[3 + i]; } for(let i = 0; i < y; i++){ arr2[i] = inputArr[3 + x + i]; } for(let i = 0; i < x; i++){ let arr4 = []; for(let j = 0; j < z; j++){ arr4.push(0); } arr3.push(arr4); } for(let i = 0; i < x; i++){ for(let j = 0; j < z; j++){ let sum = 0; for(let k = 0; k < y; k++){ sum += arr1[i][k] * arr2[k][j]; } arr3[i][j] = sum; } } for(let i = 0; i < arr3.length; i++){ console.log(arr3[i].join(" ")); } }