题解 | #矩阵乘法#

矩阵乘法

https://www.nowcoder.com/practice/ebe941260f8c4210aa8c17e99cbc663b

新思路

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 a1 = await readline()
    let a2 = await readline()
    let a3 = await readline()
    let arr1 = [],arr2 = []
    for(let i = 0;i<a1;i++){
        arr1.push((await readline()).split(" ").map(v => +v))
    }
    for(let i = 0;i<a2;i++){
        arr2.push((await readline()).split(" ").map(v => +v))
    }
    let add = []
    for(let i = 0;i<arr1.length;i++){
        let sumArr = []
        for(let j = 0;j<arr2[0].length;j++){
            let sum = 0;
            sum = arr1[i].reduce((pre,cur,k) => pre = pre +cur*arr2[k][j],0)
            sumArr.push(sum)
        }
        add.push(sumArr)
    }
    add.forEach(v => console.log(v.join(" ")))
}()

全部评论

相关推荐

ddd7_:跟我一模一样,加微信的hr都同一个,扫码了白年书人查看图片
点赞 评论 收藏
分享
11-17 14:18
门头沟学院 C++
代码飞升_不回私信人...:这种感觉还好。只是你写一个PPT,可能他面的快一点而已。那种让你写什么方案,写什么代码的那种。就没必要去了。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务