就是简单的字符串匹配,运行时间:49ms超过94.06% 用Java提交的代码,占用内存:10648KB超过94.53%用Java提交的代码
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
private static String[][] twos = {{"reset", "board", "board fault"},//reset board board fault
{"board", "add", "where to add"},//board add where to add
{"board", "delete", "no board at all"},//board delete no board at all
{"reboot", "backplane", "impossible"},//reboot backplane impossible
{"backplane", "abort", "install first"}};//backplane abort install first
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
while (s != null) {
String[] t = s.split(" ");
if (t.length == 1) {
if ("reset".startsWith(s)) {
System.out.println("reset what");
} else {
System.out.println("unknown command");
}
} else if (t.length == 2) {
int matchCount = 0;
int matchId = 0;
for (int i = 0; i < twos.length; i++) {
if (twos[i][0].startsWith(t[0]) && twos[i][1].startsWith(t[1])) {
matchCount++;
matchId = i;
}
}
if (matchCount == 1) {
System.out.println(twos[matchId][2]);
} else {
System.out.println("unknown command");
}
}
s = br.readLine();
}
}
}

京公网安备 11010502036488号