题解 | #扑克牌大小#

扑克牌大小

https://www.nowcoder.com/practice/d290db02bacc4c40965ac31d16b1c3eb

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.hasNextInt()) { // 注意 while 处理多个 case
        //     int a = in.nextInt();
        //     int b = in.nextInt();
        //     System.out.println(a + b);
        // }
        String line = in.nextLine();
        String s = "3 4 5 6 7 8 9 10 J Q K A 2 joker JOKER";
        String s1 = line.split("-")[0];
        String[] cs1 = s1.split(" ");
        String s2 = line.split("-")[1];
        String[] cs2 = s2.split(" ");
        int len1 = cs1.length;
        int len2 = cs2.length;
        if (s1.contains("joker") && s1.contains("JOKER")) {
            System.out.print(s1);
            return;
        }
        if (s2.contains("joker") && s2.contains("JOKER")) {
            System.out.print(s2);
            return;
        }

        if (len1 == 4 && len2 == 4) {
            if (s.indexOf(cs1[0]) > s.indexOf(cs2[0])) {
                System.out.print(s1);
                return;
            } else {
                System.out.print(s2);
                return;
            }
        }

        if (len1 != len2) {
            if (len1 == 4) {
                System.out.print(s1);
                return;
            }
            if (len2 == 4) {
                System.out.print(s2);
                return;
            }
            System.out.print("ERROR");
            return;
        } else {
            if (len1 == 5) {
                if (s.indexOf(cs1[4]) > s.indexOf(cs2[4])) {
                    System.out.print(s1);
                    return;
                } else {
                    System.out.print(s2);
                    return;
                }
            } else {
                if (s.indexOf(cs1[0]) > s.indexOf(cs2[0])) {
                    System.out.print(s1);
                    return;
                } else {
                    System.out.print(s2);
                    return;
                }
            }
        }
    }
}

全部评论

相关推荐

笑着秋招😊:我一直认为努力有回报是一件很幸福很幸福的事情,恭喜你
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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