题解 | #配置文件恢复#不如先把命令拆开

配置文件恢复

https://www.nowcoder.com/practice/ca6ac6ef9538419abf6f883f7d6f6ee5

import java.util.Objects;
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        String[][] command = {
                {"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"},
                {"he", "he", "unknown command"}
        };
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            String[] input = in.nextLine().split(" ");
            String output = "unknown command";
            int matchCount = 0;
            for (String[] strings : command) {
                if (input.length == 1) {
                    if (Objects.equals(strings[1], "")) {
                        if (strings[0].startsWith(input[0])) {
                            output = strings[2];
                            matchCount++;
                        }
                    }
                } else {
                    if (strings[0].startsWith(input[0]) && strings[1].startsWith(input[1])) {
                        output = strings[2];
                        matchCount++;
                    }
                }
            }
            System.out.println(matchCount == 1 ? output : "unknown command");
        }
    }
}

全部评论

相关推荐

点赞 评论 收藏
分享
门口唉提是地铁杀:之前b站被一个游戏demo深深的吸引了。看up主页发现是个初创公司,而且还在招人,也是一天60。二面的时候要我做一个登录验证和传输文件两个微服务,做完要我推到github仓库,还要我加上jaeger和一堆运维工具做性能测试并且面试的时候投屏演示。我傻乎乎的做完以后人家跟我说一句现在暂时不招人,1分钱没拿到全是白干
你的秋招第一场笔试是哪家
点赞 评论 收藏
分享
07-09 15:14
南京大学 C++
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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