java-HJ66_配置文件恢复

java-HJ66 配置文件恢复

import java.util.HashMap;
import java.util.Scanner;

public class Main {
    
    private static final HashMap<String, String> commandMap = new HashMap<>();

    static {
        commandMap.put("reset", "reset what");
        commandMap.put("reset board", "board fault");
        commandMap.put("board add", "where to add");
        commandMap.put("board delete", "no board at all");
        commandMap.put("reboot backplane", "impossible");
        commandMap.put("backplane abort", "install first");
    }

    public static void main(String[] args) {
        Scanner in =  new Scanner(System.in);

        while (in.hasNext()){
            String command = in.nextLine();

            solution(command);
        }
    }

    /**
     * map
     * @param command
     */
    private static void solution(String command){
        String[] subCommands = command.trim().split(" ");
        int matchCount = 0;
        String matchKey = "";
        if(subCommands.length == 1){
            for(String key: commandMap.keySet()){
                String[] subKeys = key.trim().split(" ");
                if(subKeys.length == 1){
                    if(subKeys[0].startsWith(subCommands[0])){
                        matchCount++;
                        matchKey = key;
                    }
                }
            }
        }else if(subCommands.length == 2){
            for(String key: commandMap.keySet()){
                String[] subKeys = key.trim().split(" ");
                if(subKeys.length == 2){
                    if(subKeys[0].startsWith(subCommands[0]) && subKeys[1].startsWith(subCommands[1])){
                        matchCount++;
                        matchKey = key;
                    }
                }
            }
        }

        if(matchCount == 1){
            System.out.println(commandMap.get(matchKey));
        }else{
            System.out.println("unknown command");
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值