题解 | #二维数组操作#
二维数组操作
https://www.nowcoder.com/practice/2f8c17bec47e416897ce4b9aa560b7f4
const rl = require("readline").createInterface({ input: process.stdin, output: process.stdout }); let arr = [] let newArr = [] rl.on('line', (line) => { arr.push(line) }) rl.on('close', () => { // 把两组数据放到新数组 newArr.push(arr.slice(0 , 5)); newArr.push(arr.slice(5)); // 循环一下 for(let arr of newArr){ let [m, n] = arr[0].split(' ').map(Number) let [x1, y1, x2, y2] = arr[1].split(' ').map(Number) let m_insert = arr[2] let n_insert = arr[3] let [x, y] = arr[4].split(' ').map(Number) // 初始化表格 if(m <= 9 && n <= 9){ console.log(0) }else console.log(-1) // 交换单元格 if(x1 <= m-1 && y1 <= n-1 && x2 <= m-1 && y2 <= n-1){ console.log(0) }else console.log(-1) // 插入行 if(m+1 <= 9 && m_insert < m){ console.log(0) }else{ console.log(-1) } // 插入列 if(n+1 <= 9 && n_insert < n){ console.log(0) }else{ console.log(-1) } // 查询坐标 // 1、数据表回复原值 if(m+1 <= 9 && n+1 <= 9){ if(x <= m-1 && y <= n-1) console.log(0) else console.log(-1) } // 2、数据表行增加 if(m+1 <= 9 && n+1 > 9){ if(x <= 9 && y <= 8) console.log(0) else console.log(-1) } // 3、数据表列增加 if(m+1 > 9 && n+1 <= 9){ if(x <= 8 && y <= 9) console.log(0) else console.log(-1) } } })
除了繁琐没别的说……完全没用到任何技巧,全是条件硬怼,这题有没有更好解法?