题解 | #矩阵乘法#
矩阵乘法
https://www.nowcoder.com/practice/ebe941260f8c4210aa8c17e99cbc663b
const rl = require("readline").createInterface({ input: process.stdin }); const inputArr = [] rl.on('line',line => { inputArr.push(line.trim()) }) rl.on('close',() => { const arr1 = [] const arr2 = [] const x = parseInt(inputArr[0]) const y = parseInt(inputArr[1]) const z = parseInt(inputArr[2]) for(let i = 0;i < x;i++) { arr1[i] = inputArr[3 + i].split(' ').map(e => parseInt(e)) } for(let i = 0;i < y;i++) { arr2[i] = inputArr[3 + x + i].split(' ').map(e => parseInt(e)) } const res = [] for(let i = 0;i < x;i++) { res[i] = [] for(let j = 0;j < z;j++) { let t = 0 for(let k = 0;k < y;k++) { t += arr1[i][k] * arr2[k][j] } res[i][j] = t } } res.forEach(e => console.log(e.join(' '))) })
套公式即可