题解 | #配置文件恢复#
配置文件恢复
http://www.nowcoder.com/practice/ca6ac6ef9538419abf6f883f7d6f6ee5
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while(in.hasNextLine()){
String l = in.nextLine();
String[] s = l.split(" ");
if(s.length == 1){
if(match("reset", s[0])){
System.out.println("reset what");
}else{
System.out.println("unknown command");
}
}else if(s.length == 2){
if(match("reset", s[0]) && match("board", s[1]) && match("reboot", s[0]) && match("backplane", s[1])){
System.out.println("unknown command");
}else if(match("board", s[0]) && match("add", s[1]) && match("backplane", s[0]) && match("abort", s[1])){
System.out.println("unknown command");
}else if(match("reset", s[0]) && match("board", s[1])){
System.out.println("board fault");
}else if(match("board", s[0]) && match("add", s[1])){
System.out.println("where to add");
}else if(match("board", s[0]) && match("delete", s[1])){
System.out.println("no board at all");
}else if(match("reboot", s[0]) && match("backplane", s[1])){
System.out.println("impossible");
}else if(match("backplane", s[0]) && match("abort", s[1])){
System.out.println("install first");
}else{
System.out.println("unknown command");
}
}
}
}
public static boolean match(String s1, String s2){
if(s2.length() > s1.length()){
return false;
}
for(int i = 0; i < s2.length(); i++){
if(s1.charAt(i) != s2.charAt(i)){
return false;
}
}
return true;
}
}