题解 | #矩阵乘法计算量估算#
矩阵乘法计算量估算
https://www.nowcoder.com/practice/15e41630514445719a942e004edc0a5b
const readline = require("readline") let rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); let count = null let lines = [] let rules = '' rl.on('line',(line)=>{ if(!count){ count = line }else{ if(lines.length<count){ lines.push(line.split(' ').map(Number)) }else{ rules = line getTimes(lines,rules) } } }) function getTimes(lines,rules){ let map={} let asc = 'A'.charCodeAt() lines.forEach((item,index)=>{ let asc1 = String.fromCharCode(asc+index) map[asc1] = item }) let temp =[] let times = 0 for(let i =0;i<rules.length;i++){ if(rules[i]==='('){ temp.push(rules[i]) } if(/[A-Z]/.test(rules[i])){ temp.push(map[rules[i]]) } if(rules[i]===')'){ let right = temp.pop() let left = temp.pop() temp.pop() let newItem = [left[0],right[1]] temp.push(newItem) times = times+(left[0]*left[1]*right[1]) } } console.log(times) }