题解 | #配置文件恢复#
配置文件恢复
http://www.nowcoder.com/practice/ca6ac6ef9538419abf6f883f7d6f6ee5
import java.io.*;
import java.util.*;
public class Main{
public static void main(String[] args)throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
HashMap<String,String> hmap=new HashMap<>();
hmap.put("reset","reset what");
hmap.put("reset board","board fault");
hmap.put("board add","where to add");
hmap.put("board delete","no board at all");
hmap.put("reboot backplane","impossible");
hmap.put("backplane abort","install first");
String[][] strarr= new String[5][2];
strarr[0][0]="reset";strarr[0][1]="board";
strarr[1][0]="board";strarr[1][1]="add";
strarr[2][0]="board";strarr[2][1]="delete";
strarr[3][0]="reboot";strarr[3][1]="backplane";
strarr[4][0]="backplane";strarr[4][1]="abort";
String str="";
while((str=br.readLine())!=null){
String[] arr=str.split(" ");
int len = arr.length;
if(len == 1 && pipei(arr[0],strarr[0][0])){
out.println(hmap.get(strarr[0][0]));
out.flush();
}
else if(len==2){
int count = 0;
int index=0;
for(int i=0;i<strarr.length;i++){
if(pipei(arr[0],strarr[i][0]) && pipei(arr[1],strarr[i][1])) {count++;index=i;}
}
if(count==1) {
String ans=strarr[index][0]+" "+strarr[index][1];
out.println(hmap.get(ans));out.flush();
}
else{
out.println("unknown command");out.flush();
}
}
else{
out.println("unknown command");out.flush();
}
}
}
static boolean pipei(String s1,String s2){
for(int i=0;i<s1.length();i++){
if(s1.charAt(i) != s2.charAt(i)) return false;
}
return true;
}
}
import java.util.*;
public class Main{
public static void main(String[] args)throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
HashMap<String,String> hmap=new HashMap<>();
hmap.put("reset","reset what");
hmap.put("reset board","board fault");
hmap.put("board add","where to add");
hmap.put("board delete","no board at all");
hmap.put("reboot backplane","impossible");
hmap.put("backplane abort","install first");
String[][] strarr= new String[5][2];
strarr[0][0]="reset";strarr[0][1]="board";
strarr[1][0]="board";strarr[1][1]="add";
strarr[2][0]="board";strarr[2][1]="delete";
strarr[3][0]="reboot";strarr[3][1]="backplane";
strarr[4][0]="backplane";strarr[4][1]="abort";
String str="";
while((str=br.readLine())!=null){
String[] arr=str.split(" ");
int len = arr.length;
if(len == 1 && pipei(arr[0],strarr[0][0])){
out.println(hmap.get(strarr[0][0]));
out.flush();
}
else if(len==2){
int count = 0;
int index=0;
for(int i=0;i<strarr.length;i++){
if(pipei(arr[0],strarr[i][0]) && pipei(arr[1],strarr[i][1])) {count++;index=i;}
}
if(count==1) {
String ans=strarr[index][0]+" "+strarr[index][1];
out.println(hmap.get(ans));out.flush();
}
else{
out.println("unknown command");out.flush();
}
}
else{
out.println("unknown command");out.flush();
}
}
}
static boolean pipei(String s1,String s2){
for(int i=0;i<s1.length();i++){
if(s1.charAt(i) != s2.charAt(i)) return false;
}
return true;
}
}