题解 | #扑克牌大小#
扑克牌大小
https://www.nowcoder.com/practice/d290db02bacc4c40965ac31d16b1c3eb
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Map<String, Integer> table = new HashMap<String, Integer>() { { put("3", 0);put("4", 1);put("5", 2);put("6", 3);put("7", 4); put("8", 5);put("9", 6);put("10", 7);put("J", 8);put("Q", 9); put("K", 10);put("A", 11);put("2", 12);put("joker", 13);put("JOKER", 14); } }; //"joker", "JOKER", "2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "4", "3"}; Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 while (in.hasNextLine()) { // 注意 while 处理多个 case String line = in.nextLine(); String[] lineSplit = line.split("-"); String[] first = lineSplit[0].split(" "); String[] seccond = lineSplit[1].split(" "); String max = "ERROR"; if(first.length == seccond.length){ // 相等时比较复杂 查表最方便 if(table.get(first[0]) > table.get(seccond[0])){ max = lineSplit[0]; } else { max = lineSplit[1]; } } else if(first.length == 2){ if(first[0].equals("joker")){ max = lineSplit[0]; } else if(seccond.length == 4){ max = lineSplit[1]; } } else if(seccond.length == 2){ if(seccond[0].equals("joker")){ max = lineSplit[1]; } else if(first.length == 4){ max = lineSplit[0]; } } else if(first.length == 4){ max = lineSplit[0]; } else if(seccond.length == 4){ max = lineSplit[1]; } System.out.println(max); } } }