题解 | #求最小公倍数#
扑克牌大小
http://www.nowcoder.com/practice/d290db02bacc4c40965ac31d16b1c3eb
将所有的情况都处理一遍,都不符合的就是无法比较
- 存在王炸其余不比较直接输出王炸
- 同规则下比较,第一个小的牌,绝对是小的
- 不同规则下只有一组是王炸或者是炸弹的情况,王炸第一中情况直接包含,所以不同规则只剩下一组是炸弹,一组是非炸弹,炸弹大
- 若以上三种情况都不符合,那么就是无法比较的情况
import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
HashMap<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);
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextLine()) { // 注意 while 处理多个 case
String[] abs = in.nextLine().split("-");
String[] a = abs[0].split(" ");
String[] b = abs[1].split(" ");
if ((a[0].toLowerCase().equals("joker") && a.length == 2) || (b[0].toLowerCase().equals("joker") && b.length == 2)) {
// 存在王炸
System.out.println("joker JOKER");
} else if (a.length == b.length) { // 同规则下比较
// 同规则下比较大小即可
if (map.get(a[0]) > map.get(b[0])) {
System.out.println(abs[0]);
} else {
System.out.println(abs[1]);
}
} else if (a.length == 4 || b.length == 4) { // 不同规则下进行比较(只剩下一个炸弹,一个其余的,王炸情况)
// 输出炸弹
System.out.println(a.length == 4 ? abs[0] : abs[1]);
} else {
// 无法比较
System.out.println("ERROR");
}
}
}
}