HW-文件恢复-测试300

it2024-10-07  16

//package t0817; import java.util.*; public class FileRelive {//类名换成Main public static void main(String[] args){ // System.out.println("请按要求输入一组指令,换行输入:"); Scanner Src= new Scanner(System.in); Vector<String> vec=new Vector<String>(); int count=0; String str = ""; while(Src.hasNextLine()){ str=Src.nextLine(); if(str.equals(""))break; vec.add(str); // 入队 count++; } for(int i=0;i<count;i++){ System.out.println(FileLiveExe(vec.elementAt(i))); } } static String[] commands = {"reset","reset board","board add","board delet","reboot backplane","backplane abort"}; static String[] result = {"reset what","board fault","where to add","no board at all","impossible","install first"}; public static String FileLiveExe(String str1){ String strout=""; String str2[]=str1.split(" "); //空格分开的 if(str2.length==1){ //长度为1时 if(commands[0].startsWith(str2[0])) //匹配第一个命令 strout=result[0] ; else { for(int i=1;i<commands.length;i++){ //匹配后面几个命令 if(commands[i].startsWith(str1)){ strout="unkown command"; break; } } if(strout=="") // 都不匹配 strout="unkown command"; } }else if(str2.length==2){ int flag=0; //找到啊标志位 int index=-1; //保存命令行数 for(int j=1;j<commands.length;j++){ String temp[]=commands[j].split(" ");//空格先分隔一下命令 if(temp[0].startsWith(str2[0]) && temp[1].startsWith(str2[1])){ //如果两个分别匹配 index=j; flag++; } } if(flag==1) {strout=result[index];} //赋值 else strout="unkown command"; }else{ strout="unkown command"; } return strout; } }

 

转载于:https://www.cnblogs.com/snowwhite/p/4738465.html

最新回复(0)