题解 | #扑克牌大小#
扑克牌大小
http://www.nowcoder.com/practice/d290db02bacc4c40965ac31d16b1c3eb
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
Map<String,Integer> map = new HashMap<>();
map.put("3", 3);
map.put("4", 4);
map.put("5", 5);
map.put("6", 6);
map.put("7", 7);
map.put("8", 8);
map.put("9", 9);
map.put("10", 10);
map.put("J", 11);
map.put("Q", 12);
map.put("K", 13);
map.put("A", 14);
map.put("2", 15);
map.put("joker", 17);
map.put("JOKER", 18);
while(sc.hasNext()){
String[] arr = sc.nextLine().split("-");
String str1 = arr[0];
String str2 = arr[1];
String[] arr1 = arr[0].split(" ");
String[] arr2 = arr[1].split(" ");
int n1 = map.get(arr1[0]);
int n2 = map.get(arr2[0]);
//题目已给两副牌不会相等条件,放心判断
//其中一个为王炸的情况
if(str1.equals("joker JOKER") || str1.equals("JOKER joker")){
System.out.println(str1);
}else if(str2.equals("joker JOKER") || str2.equals("JOKER joker")){
System.out.println(str2);
//炸弹判断情况
}else if(isBoom(str1) && isBoom(str2)){
System.out.println(n1 > n2 ? str1 : str2);
}else if(isBoom(str1)){
System.out.println(str1);
}else if(isBoom(str2)){
System.out.println(str2);
//既不是王炸也不是炸弹,利用数组元素个数相同进行判断
}else if(arr1.length == arr2.length){
System.out.println(n1 > n2 ? str1 : str2);
}else{
System.out.println("ERROR");
}
}
}
//判断是不是炸弹
public static boolean isBoom(String s){
String[] ss = s.split(" ");
if(ss.length != 4) return false;
String cur = ss[0];
for(String st : ss){
if(!cur.equals(st)) return false;
}
return true;
}
}