题解 | 矩阵乘法

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void async function () {
    // Write your code here
  let firRow = await readline()
  let RowAndCol = await readline()
  let senCol = await readline()
  let matrix1 = []
  let matrix2 = []
  let res = Array.from({ length: firRow }, () => Array.from({ length: senCol }, () => 0));
 for(let q=0; q<firRow; q++) {
    let tempRow = await readline()
    matrix1.push(tempRow.split(" ").map(Number))
 }
 for(let l=0; l<RowAndCol; l++) {
    let tempRow = await readline()
    matrix2.push(tempRow.split(" ").map(Number))
 }
  for (let i = 0; i < firRow; i++) {
    for (let j = 0; j < senCol; j++) {
        for (let k = 0; k < RowAndCol; k++) {
            res[i][j] += matrix1[i][k] * matrix2[k][j];
        }
    }
}
res.forEach((item) => {
    let str = ''
    item.forEach((i) => {
     str += i + " "
    })
    console.log(str)
})
}()

全部评论

相关推荐

2024-12-02 22:30
西安理工大学 Java
M_bao:简历排版换一下吧,第二个项目换了吧,咱门双非学历本来就不行还用这种项目太掉分了,300沟通一个要简历你打招呼也有问题。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务