ファーウェイ試験問題記録2

9304 ワード

import java.util.*;
import java.util.Map.Entry;
public class Huawei {
	
	
		public static void main(String args[]){
			fitOrder();
			//fun();
			//theLastLength();
			//change();
			//reversInt();
			// deleteStr();
			//fitOrder();
//			sort();
//			Scanner n = new Scanner(System.in);
//			
//			String a="";
//			String b="";
//			
//			//          
//			 a=n.nextLine();
//			 b=n.nextLine();
//			 
//			System.out.println(a);
//			System.out.println(b);	
//			 
//			//     a,b   
//			int aLength=a.length();
//			int bLength=b.length();
//			//           
//			int length=0;
//			
//			//         a,b        +1
//			if(aLength>=bLength){				
//				length=aLength+1;
//				
//			}else {
//				length=bLength+1;
//			}
//			
//			//           ,     
//			int[] resultc = new int[length];
//			
//			int c=0;
//			
//			int bb=0;
//			int aa=0;
//			while(length>1){
//				aa=0;bb=0;
//				
//				//       a,b        ,                  0  。                     ,    0  
//				if(bLength>0){					
//					bb=Integer.valueOf(b.charAt(bLength-1)+"");					
//				}
//				if(aLength>0){					
//					aa=Integer.valueOf(a.charAt(aLength-1)+"");					
//				}
//				
//				//System.out.println("aa----"+aa+"     bb-----"+bb);
//				c=aa+bb;
//				//         ,          
//				resultc[length-1]+=c%10;
//				//   
//				resultc[length-2]=c/10;
//				
//				length--;
//				aLength--;
//				bLength--;								
//			}
//			String result="";
//			
//			//       0     0,     
//			int i =0;
//			if(resultc[0]==0){
//				
//				i=1;
//				
//			}
//			for(;i0&&(Integer.valueOf(inArray[j]) list = new ArrayList();
			for(int i=0;i  hm = new HashMap();
			hm.put("reset", "reset what");
			hm.put("reset board", "board fault");
			hm.put("board add", "where to add");
			hm.put("board delet", "no board at all");
			hm.put("reboot backplane", "impossible");
			hm.put("backplane abort", "install first");
			
			ArrayList array = new ArrayList();//       
			
			ArrayList arraySpace = new ArrayList();//            
			ArrayList arraySpaceMap = new ArrayList();//    map key        
			Scanner scn = new Scanner(System.in);
			String str;
			while(true){
				
				str=scn.nextLine();
				arraySpace.clear();
				arraySpaceMap.clear();
				
				arraySpace=isContainSpace(str);
				int size = arraySpace.size();
				int count=0;
				//     ,   ,    
				String entryValue="";
				String entryKey="";
				if(size==1){
					
					
					
					//  MAP
					for(Entry entry : hm.entrySet()){
						
						entryKey = entry.getKey();
						arraySpaceMap=isContainSpace(entryKey);
						int mapsize=arraySpaceMap.size();
						
						if(mapsize==1&&entryKey.startsWith(str)){
							entryValue = entry.getValue();
							count++;						
						}
						
					}
					
					
				}else if(size==2){
					
					for(Entry entry:hm.entrySet()){    
						entryKey = entry.getKey();
						arraySpaceMap=isContainSpace(entryKey);
						int mapsize=arraySpaceMap.size();
						//  Map    ,    unkown command
						if(mapsize==1){
							
							
							
						}else if(mapsize==2){
							if(arraySpaceMap.get(0).startsWith(arraySpace.get(0))&&arraySpaceMap.get(1).startsWith(arraySpace.get(1))){
								entryValue = entry.getValue();
								count++;
							}
							
							
						}
						
					}
					
					
				}
				if(count==1){
					
					System.out.println(entryValue);
					
				}else{
					
					System.out.println("unkown command");
					
				}
				
			}
			
//			//              
//			while (!"".equals(line=scn.nextLine())) {
//			array.add(line);
//			}
//			//           
//			
//			for(String str : array){
//				
//				
//				
//			}
			
			
			
			
			//System.out.println(substr1+"        "+substr2);
			
			
//			}
			
			
			
		}
		
		public static ArrayList isContainSpace(String str){
			
			ArrayList list = new ArrayList();
			int index =0;//       
			
			index = str.indexOf(" ");
			
			//      ,    LIST,     ,           LIST
			if(index<0){
				
				list.add(str);
				
			}else{
				
				list.add(str.substring(0, index));
				list.add(str.substring(index+1, str.length()));
				
			}
			return list;
		}
		
		//                ,       
		public static void deleteStr(){
			
			Scanner n = new Scanner(System.in);
			String str =  n.nextLine();
			
			//char[] charArray= str.toCharArray();
			HashMap hm = new HashMap();
			String s = "";
			
			for(int i=0;i> entryset = hm.entrySet();
			Iterator iter = entryset.iterator();
			
			Entry entry = (Entry)iter.next();
			int smallValue = entry.getValue();
			int value=0;
			
			//System.out.println(smallValue+"---------smallValue");
			while(iter.hasNext()){
				
			   entry = (Entry)iter.next();
			   value = entry.getValue();
			   
			   //System.out.println(value+"---------value");
			   
			   if(value list = new ArrayList();
			for(Entry entry_a:hm.entrySet()){
				
				if(entry_a.getValue()==smallValue){					
					list.add(entry_a.getKey());					
				}				
			}
			
			//System.out.println(list);
			for(String l:list){
				
				str=str.replace(l, "");
				
			}
			
			System.out.println(str);
		}
		
		//       ,    
		public static void reversInt(){
			
			Scanner n = new Scanner(System.in);
			
			while(true){
				
				int i = n.nextInt();
				
				
				int length = 0;
				
				int sum = 0;
				
				while(i>0){
					
					sum=sum*10+i%10;
					i=i/10;
					length++;
				}
				
				
				System.out.println(length+" "+sum);
			}
			

		}
		
		//    
		public static void change(){
			
			Scanner n = new Scanner(System.in);
			String str = n.nextLine();
			String str_new = "";
			
			for(int i = 0;i=97&&asci<=99){
					str_new+="2";
				}else if(asci>=100&&asci<=102){
					str_new+="3";
				}else if(asci>=103&&asci<=105){
					str_new+="4";
				}else if(asci>=106&&asci<=108){
					str_new+="5";
				}else if(asci>=109&&asci<=111){
					str_new+="6";
				}else if(asci>=112&&asci<=115){
					str_new+="7";
				}else if(asci>=116&&asci<=118){
					str_new+="8";
				}else if(asci>=119&&asci<=122){
					str_new+="9";
				}else if(asci>=65&&asci<90){					
					str_new+=String.valueOf((char)(asci+33));
				}else if(asci==90){					
					str_new+="a";
				}else
					str_new+=s;
			}
			
			System.out.println(str_new);
			
		}
		
		//        
		public static void theLastLength(){
			
			Scanner n = new Scanner(System.in);
			String str  = n.nextLine();
			
			
			int index = 0;
			index = str.lastIndexOf(" ");
			
			int result = str.length() - index -1;

			System.out.println(result);
			
			
			
			
			
			
		}
		
		public static void fun(){
			
			Scanner n = new Scanner(System.in);
			
			while(true){
				
				String str = n.nextLine();
				password(str);
				
			}
			
		}
		//      
		public static void password(String str){

				int length = str.length();
				
				
				
				//    
				if(length<=8){
					
					System.out.println("NG");
					return;
				}
				
				int count[] = {0,0,0,0};
				int sum=0;
				for(int i=0;i=48&&assci<=57){
						
						count[0]=1;
					}else if(assci>=65&&assci<=90){//A~Z
						
						count[1]=1;
					}else if(assci>=97&&assci<=122){//a~z
						count[2]=1;
					}else count[3]=1;
				}
				//        
				
				for(int i=0;i<4;i++){
					//System.out.println(count[i]);
					if(count[i]==1){
						
						sum++;
					}
					
				}
				if(sum<3){
					//System.out.println("sum  <  3");
					System.out.println("NG");
					return;
					
				}
				
				//      
				int step=1;
				boolean flag = true;
				while(step