题解 | #扑克牌大小#

扑克牌大小

https://www.nowcoder.com/practice/d290db02bacc4c40965ac31d16b1c3eb?tpId=37&tags=&title=&difficulty=4&judgeStatus=&rp=1&sourceUrl=%2Fexam%2Foj%2Fta%3Fpage%3D2%26tpId%3D37%26type%3D37&gioEnter=menu

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String p = in.nextLine();
            String[] pp = p.split("-");
            p = p.replaceAll("joker","X");
            p = p.replaceAll("JOKER","Y");
            String[] ppp = p.split("-");
            String[] pp0 = ppp[0].split(" ");
            String[] pp1 = ppp[1].split(" ");
            int l1 = pp0.length;
            int l2 = pp1.length;
            if(ppp[0].equals("X Y") || ppp[1].equals("X Y")){
                System.out.println("joker JOKER");
            } else {
                if(l1 != l2){
                    if(l1!=4 && l2!=4){
                        System.out.println("ERROR");
                    } else if(l1==4){
                        System.out.println(pp[0]);
                    } else if(l2==4){
                        System.out.println(pp[1]);
                    }
                }else{
                    String x = pp0[0];
                    String y = pp1[0];
                    String pow = "34567890JQKA2XY";
                    int px = pow.indexOf(x.replaceAll("1",""));
                    int py = pow.indexOf(y.replaceAll("1",""));
                    System.out.println(px>py?pp[0]:pp[1]);
                }
            }
        }
    }
}

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务