题解 | #扑克牌大小#

扑克牌大小

https://www.nowcoder.com/practice/0a92c75f5d6b4db28fcfa3e65e5c9b3f

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextLine()) {
            String str = in.nextLine();
            String firstOri = str.split("-")[0];
            String secondOri = str.split("-")[1];
            String input = str.replace("2", "15").replace("joker", "16").replace("JOKER",
                           "17").replace("J", "11").replace("Q", "12").replace("K", "13").replace("A","14");
            String[] firstArray = input.split("-")[0].split("\\s+");
            String[] secondArray = input.split("-")[1].split("\\s+");
            String max = "";
            if (firstArray.length == 1) { //1张
                if (secondArray.length == 1) {
                    if (Integer.parseInt(firstArray[0]) > Integer.parseInt(
                                secondArray[0])) { //两个单张
                        max = firstOri;
                    } else {
                        max = secondOri;
                    }
                } else if (secondArray.length == 2) {
                    if (secondArray[0].equals("16") || secondArray[0].equals("17")) { //对王
                        max = secondOri;
                    }else {
                        max = "ERROR";
                    }
                } else if (secondArray.length == 4) { //四个相同牌炸弹
                    max = secondOri;
                } else {
                    max = "ERROR";
                }
            } else if (firstArray.length == 2) { //2张
                if (firstArray[0].equals("16") || firstArray[0].equals("17")) { //对王
                    max = firstOri;
                } else if (secondArray.length == 2) {
                    if (secondArray[0].equals("16") || secondArray[0].equals("17")) { //对王
                        max = secondOri;
                    } else if (Integer.parseInt(firstArray[0]) > Integer.parseInt(
                                   secondArray[0])) { //俩个对
                        max = firstOri;
                    } else {
                        max = secondOri;
                    }
                } else if (secondArray.length == 4) {
                    max = secondOri;
                } else {
                    max = "ERROR";
                }
            } else if (firstArray.length == 3) { //3张
                if (secondArray.length == 2 && (secondArray[0].equals("16") ||
                                                secondArray[0].equals("17"))) {
                    max = secondOri;
                } else if (secondArray.length == 3) {
                    if (Integer.parseInt(firstArray[0]) > Integer.parseInt(secondArray[0])) {
                        max = firstOri;
                    } else {
                        max = secondOri;
                    }
                } else if (secondArray.length == 4) {
                    max = secondOri;
                } else {
                    max = "ERROR";
                }
            } else if (firstArray.length == 4) { //四张
                if (secondArray.length == 2 && (secondArray[0].equals("16") ||
                                                secondArray[0].equals("17"))) {
                    max = secondOri;
                } else if (secondArray.length == 4) {
                    if (Integer.parseInt(firstArray[0]) > Integer.parseInt(secondArray[0])) {
                        max = firstOri;
                    } else {
                        max = secondOri;
                    }
                } else {
                    max = firstOri;
                }
            } else if (firstArray.length == 5) {
                if (secondArray.length == 4 && (secondArray[0].equals("16") ||
                                                secondArray[0].equals("17"))) {
                    max = secondOri;
                } else if (secondArray.length == 5) {
                    if (Integer.parseInt(firstArray[0]) > Integer.parseInt(secondArray[0])) {
                        max = firstOri;
                    } else {
                        max = secondOri;
                    }
                } else {
                    max = "ERROR";
                }
            }
            System.out.println(max);
        }

    }

}

#算法小白#
全部评论

相关推荐

不愿透露姓名的神秘牛友
02-14 11:10
点赞 评论 收藏
分享
想要offer的牛油果很大方:老哥,你啥时候面的,有timeline吗
点赞 评论 收藏
分享
01-26 22:20
已编辑
门头沟学院 Java
Java抽象带篮子:项目很nb了,现在好好准备八股和算法吧,早点找实习,可以看看我的置顶帖子。帖子里写了怎么改简历,怎么包装实习经历,还有2个高质量可速成的项目话术,和我的牛客八股笔记专栏
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务