题解 | #字符串加密#

扑克牌大小

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

使用HashMap存储扑克点数,key为字面值,value为实际大小。
列出所有场景,暴力输出。

import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextLine()) {
            String input = scanner.nextLine();
            String str1 = input.split("-")[0];
            String str2 = input.split("-")[1];
            System.out.println(bigger(str1, str2));
        }
    }

    public static String bigger(String str1, String str2) {
        HashMap<String, Integer> hm = new HashMap<>();
        for (int i = 3, j = 1; i < 11; i++, j++) {
            hm.put(String.valueOf(i), j);
        }
        hm.put("J", 9);
        hm.put("Q", 10);
        hm.put("k", 11);
        hm.put("A", 12);
        hm.put("2", 13);
        hm.put("joker", 14);
        hm.put("JOKER", 15);

        String[] strArr1 = str1.split(" ");
        String[] strArr2 = str2.split(" ");
        if (strArr1.length == 1) {
            if (strArr2.length == 1) {
                if (hm.get(strArr1[0]) > hm.get(strArr2[0])) {
                    return str1;
                } else {
                    return str2;
                }
            }
            if (strArr2.length == 2) {
                if (strArr2[0].equalsIgnoreCase("joker")) {
                    return str2;
                } else {
                    return "ERROR";
                }
            }
            if (strArr2.length == 3 || strArr2.length == 5) {
                return "ERROR";
            }

            if (strArr2.length == 4) {
                return str2;
            }
        }
        if (strArr1.length == 2) {
            if (strArr2.length == 1) {
                if (strArr1[0].equalsIgnoreCase("joker")) {
                    return str1;
                } else {
                    return "ERROR";
                }
            }
            if (strArr2.length == 2) {
                if (hm.get(strArr1[0]) > hm.get(strArr2[0])) {
                    return str1;
                } else {
                    return str2;
                }
            }
            if (strArr2.length == 3 || strArr2.length == 5) {
                if (strArr1[0].equalsIgnoreCase("joker")) {
                    return str1;
                } else {
                    return "ERROR";
                }
            }

            if (strArr2.length == 4) {
                if (strArr1[0].equalsIgnoreCase("joker")) {
                    return str1;
                } else {
                    return str2;
                }
            }
        }
        if (strArr1.length == 3) {
            if (strArr2.length == 1) {
                return "ERROR";
            }
            if (strArr2.length == 2) {
                if (strArr2[0].equalsIgnoreCase("joker")) {
                    return str2;
                } else {
                    return "ERROR";
                }
            }
            if (strArr2.length == 3) {
                if (hm.get(strArr1[0]) > hm.get(strArr2[0])) {
                    return str1;
                } else {
                    return str2;
                }
            }

            if (strArr2.length == 4) {
                return str2;
            }
            if (strArr2.length == 5) {
                return "ERROR";
            }
        }
        if (strArr1.length == 4) {
            if (strArr2.length == 1) {
                return str1;
            }
            if (strArr2.length == 2) {
                if (strArr2[0].equalsIgnoreCase("joker")) {
                    return str2;
                } else {
                    return str1;
                }
            }
            if (strArr2.length == 3 || strArr2.length == 5) {
                return str1;
            }

            if (strArr2.length == 4) {
                if (hm.get(strArr1[0]) > hm.get(strArr2[0])) {
                    return str1;
                } else {
                    return str2;
                }
            }
        }
        if (strArr1.length == 5) {
            if (strArr2.length == 1) {
                return "ERROR";
            }
            if (strArr2.length == 2) {
                if (strArr2[0].equalsIgnoreCase("joker")) {
                    return str2;
                } else {
                    return "ERROR";
                }
            }
            if (strArr2.length == 3) {
                return "ERROR";
            }
            if (strArr2.length == 4) {
                return str2;
            }
            if (strArr2.length == 5) {
                if (hm.get(strArr1[0]) > hm.get(strArr2[0])) {
                    return str1;
                } else {
                    return str2;
                }
            }

        }
        return "ERROR";

    }
}


全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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