题解 | #配置文件恢复#
配置文件恢复
https://www.nowcoder.com/practice/ca6ac6ef9538419abf6f883f7d6f6ee5
const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
void async function () {
const demandMap = {
"reset":"reset what",
"reset board":"board fault",
"board add":"where to add",
"board delete":"no board at all",
"reboot backplane":"impossible",
"backplane abort":"install first"
}
while(line = await readline()){
let match = [];
let list = line.split(" ");
for(const key of Object.keys(demandMap)){
keyList = key.split(" ");
if(list.length != keyList.length) continue;
let isMatch = true;
for(let i = 0; i < list.length; i++){
if(keyList[i].indexOf(list[i]) != 0) isMatch = false;
// console.log(keyList[i],list[i]);
}
if(isMatch) match.push(key);
}
// console.log(match);
if(match.length == 1) console.log(demandMap[match[0]]);
else console.log("unknown command");
}
}()
查看22道真题和解析
