题解 | #扑克牌大小#
扑克牌大小
https://www.nowcoder.com/practice/d290db02bacc4c40965ac31d16b1c3eb
import java.util.Scanner; //先判断大小王的情况(直接返回大小王的那手牌),再判断炸弹的情况,两手都是炸弹需要比较第一张牌大小,比较大小时可将J Q K A 2 小王 大王转换为 11 12 13 14 15 16 17 ,这样比较时候就方便了 public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()){ String line = sc.nextLine(); String[] split = line.split("-"); String p1 = split[0]; String p2 = split[1]; System.out.println(biJiao(p1,p2)); } sc.close(); } public static String biJiao(String p1,String p2){ String[] sp1 = p1.split(" "); String[] sp2 = p2.split(" "); if (sp1.length==2&& "joker".equals(sp1[0].toLowerCase())){ return p1; } if (sp2.length==2 && "joker".equals(sp2[0].toLowerCase())){ return p2; } if (sp1.length==4 && sp2.length!=4){ return p1; } if (sp1.length!=4 && sp2.length==4){ return p2; } if (sp1.length==4 && sp2.length==4){ return zh(sp1[0])>zh(sp2[0])?p1:p2; } if (sp1.length==5 && sp2.length==5){ return zh(sp1[0])>zh(sp2[0])?p1:p2; } if (sp1.length==3 && sp2.length==3){ return zh(sp1[0])>zh(sp2[0])?p1:p2; } if (sp1.length==2 && sp2.length==2){ return zh(sp1[0])>zh(sp2[0])?p1:p2; } if (sp1.length==1 && sp2.length==1){ return zh(sp1[0])>zh(sp2[0])?p1:p2; } return "ERROR"; } public static int zh(String s){ if ("J".equals(s.toUpperCase())){ return 11; } if ("Q".equals(s.toUpperCase())){ return 12; } if ("K".equals(s.toUpperCase())){ return 13; } if ("A".equals(s.toUpperCase())){ return 14; } if ("2".equals(s.toUpperCase())){ return 15; } if ("joker".equals(s)){ return 16; } if ("JOKER".equals(s)){ return 17; } return Integer.valueOf(s); } }