import java.util.*; ​ public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); while (input.hasNext()) { String string=input.nextLine(); HashMap<string> hashMap=new HashMap<string>(); hashMap.put("reset","reset what"); hashMap.put("reset board","board fault"); hashMap.put("board add","where to add"); hashMap.put("board delete","no board at all"); hashMap.put("reboot backplane","impossible"); hashMap.put("backplane abort","install first"); String [] str=new String[] {"reset board","board add","board delete","reboot backplane","backplane abort"}; if (string.contains(" ")) {//先判断命令是否有空格 String [] conmand=string.split(" ");//命令成为数组 int count=0; String conmondRconment=""; for(int i = 0; i < str.length; i++){//遍历真实的命令 String []temp=str[i].split(" "); if(temp[0].contains(conmand[0])&&temp[1].contains(conmand[1])){//这里先判断是含有, if (temp[0].substring(0,conmand[0].length()).equals(conmand[0])&&temp[1].substring(0,conmand[1].length()).equals(conmand[1])) { //bo a命令只能匹配board add ,如果不加上方if判断,会出现bo a命令输出成无效命令 count++; conmondRconment=temp[0]+" "+temp[1]; } } } System.out.println(count==1?hashMap.get(conmondRconment):"unknown command"); } else { if ("reset".contains(string)) {//单个命令直接判断就行 System.out.println(hashMap.get("reset")); } else{ System.out.println("unknown command"); } } } } }</string></string>
点赞

相关推荐

点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
02-12 10:05
小米集团 算法工程师 28.0k*15.0
泡沫灬一触即破:楼上那个看来是看人拿高薪,自己又不如意搁这泄愤呢是吧,看你过往评论很难不怀疑你的精神状态
点赞 评论 收藏
分享
牛客网
牛客企业服务