题解 | #扑克牌大小#
扑克牌大小
https://www.nowcoder.com/practice/d290db02bacc4c40965ac31d16b1c3eb
思路:分八种情况:1、双方有一边是王炸;2、两边都是炸弹;3、有一边是炸弹;4、个子;5、对子;6、三个;7、顺子;8、不能进行比较
import java.util.*; import java.io.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { private static final HashMap<String, Integer> poker = new HashMap<>(); static { poker.put("3", 3); poker.put("4", 4); poker.put("5", 5); poker.put("6", 6); poker.put("7", 7); poker.put("8", 8); poker.put("9", 9); poker.put("10", 10); poker.put("J", 11); poker.put("Q", 12); poker.put("K", 13); poker.put("A", 14); poker.put("2", 15); poker.put("joker", 16); poker.put("JOKER", 17); } //构造函数初始化 // public Main() { // poker.put("3", 3); // poker.put("4", 4); // poker.put("5", 5); // poker.put("6", 6); // poker.put("7", 7); // poker.put("8", 8); // poker.put("9", 9); // poker.put("10", 10); // poker.put("J", 11); // poker.put("Q", 12); // poker.put("K", 13); // poker.put("A", 14); // poker.put("2", 15); // poker.put("joker", 16); // poker.put("JOKER", 17); // } public static void main(String[] args) throws IOException { // Scanner in = new Scanner(System.in); // Main m = new Main(); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str = ""; // 注意 hasNext 和 hasNextLine 的区别 while ((str = br.readLine()) != null) { // 注意 while 处理多个 case String[] s = str.trim().split("-"); String[] player1 = s[0].trim().split(" "); String[] player2 = s[1].trim().split(" "); //王炸 if (s[0].equals("joker JOKER") || s[1].equals("joker JOKER")) { System.out.println("joker JOKER"); //都是炸弹 } else if (player1.length == player2.length && player1.length == 4) { System.out.println(poker.get(player1[0]) >= poker.get(player2[0]) ? s[0] : s[1]); //有一边是炸弹 } else if ((player1.length == 4 && player2.length != 4 || player1.length != 4 && player2.length == 4)) { System.out.println(player1.length == 4 ? s[0] : s[1]); //个子 } else if (player1.length == 1 && player2.length == 1) { System.out.println(poker.get(player1[0]) >= poker.get(player2[0]) ? s[0] : s[1]); //三个 } else if (player1.length == 3 && player2.length == 3) { System.out.println(poker.get(player1[0]) >= poker.get(player2[0]) ? s[0] : s[1]); //顺子 } else if (player1.length >= 5 && player2.length >= 5) { System.out.println(poker.get(player1[0]) >= poker.get(player2[0]) ? s[0] : s[1]); //对子 } else if (player1.length == 2 && player2.length == 2) { System.out.println(poker.get(player1[0]) >= poker.get(player2[0]) ? s[0] : s[1]); } else System.out.println("ERROR"); } } }