题解 | #扑克牌大小#

扑克牌大小

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

解题方法

1.获取输入,使用bufferedReader,可以同时读取空格

2.判断是否有王炸,有输出并结束

3.判断两个字符数组是否相等,是进入下一步,不是的话判断是否有炸弹,有输出炸弹,没有输出错误

4.这时候必定是两幅相同类型的牌,然后自定义牌的权值使用hashmap,加入权值,然后比大小就可以了


import java.util.*;
import java.io.*;

public class Main{
    public static void main(String[] args) throws IOException{
    	  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	  String str=br.readLine();
    	  String[] temp=str.split("-");
    	  if(temp[0].equals("joker JOKER")||temp[1].equals("joker JOKER")) {
    		  System.out.println("joker JOKER");
    		  return;
    	  }
    	  String[] str1=temp[0].split(" ");
    	  String[] str2=temp[1].split(" ");
    	  if(str1.length!=str2.length){
    		  if(str1.length==4){
                  System.out.println(temp[0]);
              }
              else if(str2.length==4){
                  System.out.println(temp[1]);
              }else{
                  System.out.println("ERROR");
              }
              return;
    	  }
          
    	  HashMap<String,Integer> map=new HashMap<>();
    	  map.put("3", 1);
    	  map.put("4", 2);
    	  map.put("5", 3);
    	  map.put("6", 4);
    	  map.put("7", 5);
    	  map.put("8", 6);	
    	  map.put("9", 7);
    	  map.put("10", 8);
    	  map.put("J", 9);
    	  map.put("Q", 10);
    	  map.put("K", 11);
    	  map.put("A", 12);
    	  map.put("2", 13);
          map.put("joker", 14);
          map.put("JOKER", 15);
    	  if(map.get(str1[0])<map.get(str2[0])) {
    		  System.out.println(temp[1]);
    	  }else {
    		  System.out.println(temp[0]);
    	  }    	  
      }

}
全部评论

相关推荐

野猪不是猪🐗:我assume that你must技术aspect是solid的,temperament也挺good的,however面试不太serious,generally会feel style上不够sharp
点赞 评论 收藏
分享
强大的马里奥:不太可能,我校计算机硕士就业率99%
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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