题解 | #扑克牌大小#

扑克牌大小

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

    }

}

#算法小白#
全部评论

相关推荐

点赞 评论 收藏
分享
这算盘打的
程序员小白条:都这样的,都是潜规则,你自己说可以实习一年就行了,实习可以随便跑路的
点赞 评论 收藏
分享
05-21 15:47
门头沟学院 Java
浪漫主义的虹夏:项目有亮点吗,第一个不是纯玩具项目吗,项目亮点里类似ThreadLocal,Redis储存说难听点是花几十分钟绝大部分人都能学会,第二个轮子项目也没体现出设计和技术,想实习先沉淀,好高骛远的自嗨只会害了自己
点赞 评论 收藏
分享
06-15 02:05
已编辑
南昌航空大学 数据分析师
Eason三木:你如果想干技术岗,那几个发公众号合唱比赛的经历就去掉,优秀团员去掉,求职没用。然后CET4这种不是奖项,是技能,放到下面的专业技能里或者单独列一个英语能力。 另外好好改改你的排版,首行缩进完全没有必要,行间距好好调调,别让字和标题背景黏在一起,你下面说能做高质量PPT你得展现出来啊,你这简历排版我用PPT做的都能比你做的好。 然后自我评价,你如果要干数据工程师,抗压能力强最起码得有吧。
简历中的项目经历要怎么写
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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