题解 | #扑克牌大小#

扑克牌大小

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);
        }

    }

}

#算法小白#
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-04 14:23
steelhead:你回的有问题,让人感觉你就是来学习的
点赞 评论 收藏
分享
06-23 11:43
门头沟学院 Java
allin校招的烤冷...:我靠,今天中午我也是这个hr隔一个星期发消息给我。问的问题还是一模一样的😅
点赞 评论 收藏
分享
宇算唯航:目测实缴资本不超100W的小公司
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务