题解 | #配置文件恢复#

配置文件恢复

http://www.nowcoder.com/practice/ca6ac6ef9538419abf6f883f7d6f6ee5

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] list = {"reset","board","reboot","backplane"};
		
		while(sc.hasNextLine()){
			Scanner scanLine = new Scanner(sc.nextLine());
			if(scanLine.hasNext()){
				String str1 = scanLine.next();
				
				int cmd1 = 0;
				String cmd2 = "null";
				
				if(scanLine.hasNext()){
					cmd2 = scanLine.next();
					
					int cmd1Count = 0;
					for(int i=1; i<=4; i++){
						if(list[i-1].startsWith(str1)){
							cmd1Count++;
							cmd1 = i;
						}
					}
					
					if(cmd1Count == 1){
						switch(cmd1){
							case 1:{
								if("board".startsWith(cmd2)){
									System.out.println("board fault");
								}else{
									System.out.println("unknown command");
								}
							}break;
							
							case 2:{
								
								if("add".startsWith(cmd2)){
									System.out.println("where to add");
								}else if("delete".startsWith(cmd2)){
									System.out.println("no board at all");
								}else{
									System.out.println("unknown command");
								}
							}break;
							
							case 3:{
								
								if("backplane".startsWith(cmd2)){
									System.out.println("impossible");
								}else{
									System.out.println("unknown command");
								}
								
							}break;
							
							case 4:{
								
								if("abort".startsWith(cmd2)){
									System.out.println("install first");
								}else{
									System.out.println("unknown command");
								}
							}break;
							
						}
					}else{
						System.out.println("unknown command");
					}
				}else{
					if("reset".startsWith(str1)){
						System.out.println("reset what");
					}else{
						System.out.println("unknown command");
					}
				}
			}
			scanLine.close();
		}
		sc.close();
	}
}

全部评论

相关推荐

兄弟们,绩效自评一定得给自己打A啊!千万别谦虚给低分,不然领导正愁给谁高分,你这不就“主动请缨”了嘛,而且多数领导不会给你更高分。我几年前试用期绩效自评打了B,领导就给了同等级,还好是试用期。真别等领导主动给高评价!
准备进厂的劳伦斯很迷人:小学时候有个册子 自评 小组 老师 我谦虚打了个b 小组别人给我打b 老师来句我觉得能给他打a 但是小组长说他自评是b怎么能打高呢 那时候我才明白的道理
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务