题解 | #扑克牌大小#

扑克牌大小

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


import java.util.Scanner;
//先判断大小王的情况(直接返回大小王的那手牌),再判断炸弹的情况,两手都是炸弹需要比较第一张牌大小,比较大小时可将J Q K A 2 小王 大王转换为 11 12 13 14 15 16 17 ,这样比较时候就方便了
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()){
            String line = sc.nextLine();
            String[] split = line.split("-");
            String p1 = split[0];
            String p2 = split[1];
            System.out.println(biJiao(p1,p2));
        }
        sc.close();
    }
    public static String biJiao(String p1,String p2){
        String[] sp1 = p1.split(" ");
        String[] sp2 = p2.split(" ");
        if (sp1.length==2&& "joker".equals(sp1[0].toLowerCase())){
            return p1;
        }
        if (sp2.length==2 && "joker".equals(sp2[0].toLowerCase())){
            return p2;
        }
        if (sp1.length==4 && sp2.length!=4){
            return p1;
        }
        if (sp1.length!=4 && sp2.length==4){
            return p2;
        }
        if (sp1.length==4 && sp2.length==4){
            return zh(sp1[0])>zh(sp2[0])?p1:p2;
        }
        if (sp1.length==5 && sp2.length==5){
            return zh(sp1[0])>zh(sp2[0])?p1:p2;
        }
        if (sp1.length==3 && sp2.length==3){
            return zh(sp1[0])>zh(sp2[0])?p1:p2;
        }
        if (sp1.length==2 && sp2.length==2){
            return zh(sp1[0])>zh(sp2[0])?p1:p2;
        }
        if (sp1.length==1 && sp2.length==1){
            return zh(sp1[0])>zh(sp2[0])?p1:p2;
        }
        return "ERROR";
    }
    public static int zh(String s){
        if ("J".equals(s.toUpperCase())){
            return 11;
        }
        if ("Q".equals(s.toUpperCase())){
            return 12;
        }
        if ("K".equals(s.toUpperCase())){
            return 13;
        }
        if ("A".equals(s.toUpperCase())){
            return 14;
        }
        if ("2".equals(s.toUpperCase())){
            return 15;
        }
        if ("joker".equals(s)){
            return 16;
        }
        if ("JOKER".equals(s)){
            return 17;
        }
        return Integer.valueOf(s);
    }
}

全部评论

相关推荐

三题看不懂四题不明白二题无法AC T=int(input()) for _ in range(T): n=int(input()) s=input().split() k,mx=1,1 for i in range(len(s)-1): if len(s[i])<len(s[i+1]): k+=1 elif len(s[i])==len(s[i+1]): if s[i]<=s[i+1]: k+=1 ...
恭喜臭臭猴子:第二题用栈就行。合法的括号直接出栈了,剩下的是不合法的,肯定都得一个一个走。出入栈的过程中得记下进栈的括号的下标。最后栈里剩下的括号如果相邻两个的下标不连续,说明它们中间有一个合法的括号序列被出栈,结果加一
投递拼多多集团-PDD等公司10个岗位 > 拼多多求职进展汇总 笔试
点赞 评论 收藏
分享
03-13 16:51
已编辑
门头沟学院 硬件开发
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务