题解 | #扑克牌大小#
扑克牌大小
https://www.nowcoder.com/practice/d290db02bacc4c40965ac31d16b1c3eb
先判断类型
如果有王炸,那么直接输出
如果一方有炸 ,一方没有,那么输出炸
如果同类型,比较第一张牌
如果不同类型,那么输出error
import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
/**
判断类型
个 对子 三张 顺子
炸弹 王
*/
while (in.hasNext()) { // 注意 while 处理多个 case
String str = in.nextLine();
String[] s0 = str.split("-");
String[] s1 = s0[0].split(" ");
String[] s2 = s0[1].split(" ");
int t1 = check(s1);
int t2 = check(s2);
Map<String, Integer> map = new HashMap<>();
map.put("3", 1);
map.put("4", 2);
map.put("5",3);
map.put("6",4);
map.put("7",5);
map.put("8",6);
map.put("9",7);
map.put("10", 8);
map.put("J",9);
map.put("Q",10);
map.put("K",11);
map.put("A",12);
map.put("2",13);
map.put("joker",14);
map.put("JOKER",15);
if (t1 == 6) {
print(s1);
} else if ( t2 == 6) {
print(s2);
} else if (t1 == 4 && t2 != 4) {
print(s1);
} else if ( t2 == 4 && t1 != 4) {
print(s2);
} else if (t1 == t2) {
if (map.get(s1[0]) > map.get(s2[0]) ) {
print(s1);
} else {
print(s2);
}
} else {
System.out.print("ERROR");
}
}
}
public static void print(String[] strs) {
for (String s : strs) {
System.out.print(s + " ");
}
}
public static int check(String[] s ) {
if (s.length == 1) {
return 1;
}
if (s.length == 2 ) {
if (!"joker".equals(s[0]) ) {
return 2 ;
} else {
return 6;
}
}
if (s.length == 3) {
return 3;
}
if (s.length == 4) {
return 4;
}
if (s.length >= 5) {
return 5;
}
return 0;
}
}


