题解 | #配置文件恢复#
配置文件恢复
https://www.nowcoder.com/practice/ca6ac6ef9538419abf6f883f7d6f6ee5
const map={ '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' } const keys=Object.keys(map) while(line=readline()){ let lines=line.split(' ') let ans = keys.filter(item=>{ let items=item.split(' ') if(lines.length===items.length){ let tag=true for(let i=0;i<lines.length;i++){ if(items[i].indexOf(lines[i])!==0){ tag=false break } } return tag } }) if(ans.length===1){ console.log(map[ans[0]]) }else{ console.log('unknown command') } }