题解 | #配置文件恢复#

配置文件恢复

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");
    }
}()

全部评论

相关推荐

Java转测开第一人:这种就是饼 把应届当廉价劳动力用完然后丢掉
你觉得今年秋招难吗
点赞 评论 收藏
分享
轻絵梨花泪沾衣:南泵,大少爷驾到通通闪开
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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