题解 | #矩阵乘法#

矩阵乘法

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

while(line = readline()){
    let x = Number(line)
    let y = Number(readline())
    let z = Number(readline())
    
    const arr1 = []
    const arr2 = []
    const res = new Array(x).fill().map(() => new Array(z).fill(0))
    for(let i = 0; i < x; i++){
        arr1.push(readline().split(' ').map(item => item -0))
    }
    
    for(let i = 0; i < y; i++){
        arr2.push(readline().split(' ').map(item => item -0))
    }
    
    for(let i = 0 ;i < x; i++){
        for(let j = 0; j < z; j++){
            for(let k = 0; k < y; k++){
                res[i][j] += arr1[i][k] * arr2[k][j]
            }
        }
    }
    
    res.forEach(item => console.log(item.join(' ')))
}
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务