题解 | #扑克牌大小#
扑克牌大小
http://www.nowcoder.com/practice/d290db02bacc4c40965ac31d16b1c3eb
import java.util.*;
public class Main{
private static LinkedHashMap<String,Integer> numMap = new LinkedHashMap<>();
static{
numMap.put("JOKER",15);
numMap.put("joker",14);
numMap.put("2",13);
numMap.put("A",12);
numMap.put("K",11);
numMap.put("Q",10);
numMap.put("J",9);
numMap.put("10",8);
numMap.put("9",7);
numMap.put("8",6);
numMap.put("7",5);
numMap.put("6",4);
numMap.put("5",3);
numMap.put("4",2);
numMap.put("3",1);
}
// joker JOKER代表14,2代表13,A代表12,以此类推,0代表不是炸弹
public static int getBomp(ArrayList<String> list){
if(list.size()==2&&list.contains("joker")&& list.contains("JOKER")){
return 14;
}
if(list.size()!=4){
return 0;
}else{
String firstNum = list.get(0);
for(int i=1;i<4;i++){
if(!list.get(i).equals(firstNum)){
return 0;
}
}
return numMap.get(firstNum);
}
}
//获取顺子分数,不是顺子则是0分
public static int getShunzi(ArrayList<String> list){
if(list.size()!=5){
return 0;
}else{
if(list.contains("2")||list.contains("joker")||list.contains("JOKER")){
return 0;
}
if(list.contains("3")&&list.contains("4")&&list.contains("5")&&list.contains("6")&&list.contains("7")){
return numMap.get("3");
}else if(list.contains("4")&&list.contains("5")&&list.contains("6")&&list.contains("7")&&list.contains("8")){
return numMap.get("4");
}else if(list.contains("5")&&list.contains("6")&&list.contains("7")&&list.contains("8")&&list.contains("9")){
return numMap.get("5");
}else if(list.contains("6")&&list.contains("7")&&list.contains("8")&&list.contains("9")&&list.contains("10")){
return numMap.get("6");
}else if(list.contains("7")&&list.contains("8")&&list.contains("9")&&list.contains("10")&&list.contains("J")){
return numMap.get("7");
}else if(list.contains("8")&&list.contains("9")&&list.contains("10")&&list.contains("J")&&list.contains("Q")){
return numMap.get("8");
}else if(list.contains("9")&&list.contains("10")&&list.contains("J")&&list.contains("Q")&&list.contains("K")){
return numMap.get("9");
}else if(list.contains("10")&&list.contains("J")&&list.contains("Q")&&list.contains("K")&&list.contains("A")){
return numMap.get("10");
}else{
return 0;
}
}
}
//获取三个,两个,一个牌的分,0分代表不是纯一个数字牌
public static int getDaxiao(ArrayList<String> list){
String firstNum = list.get(0);
int n = list.size();
for(int i=1;i<n;i++){
if(!list.get(i).equals(firstNum)){
return 0;
}
}
return numMap.get(firstNum);
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
ArrayList<String> list1 = new ArrayList<>();
ArrayList<String> list2 = new ArrayList<>();
while(sc.hasNext()){
String str = sc.nextLine();
String[] strs = str.split("\\-");
String str1 = strs[0];
String str2 = strs[1];
String[] str1s = str1.split(" ");
String[] str2s = str2.split(" ");
for(int i=0;i<str1s.length;i++){
list1.add(str1s[i]);
}
for(int i=0;i<str2s.length;i++){
list2.add(str2s[i]);
}
int n1 = list1.size();
int n2 = list2.size();
int b1 = getBomp(list1);
int b2 = getBomp(list2);
if(b1>b2){
System.out.println(str1);
}else if(b1<b2){
System.out.println(str2);
}else if(n1!=n2){
System.out.println("ERROR");
}else{
int shun1 = getShunzi(list1);
int shun2 = getShunzi(list2);
if(shun1>shun2){
System.out.println(str1);
}else if(shun1<shun2){
System.out.println(str2);
}else{
int daxiao1 = getDaxiao(list1);
int daxiao2 = getDaxiao(list2);
if(daxiao1>daxiao2){
System.out.println(str1);
}else if(daxiao1<daxiao2){
System.out.println(str2);
}else{
}
}
}
}
}
}
public class Main{
private static LinkedHashMap<String,Integer> numMap = new LinkedHashMap<>();
static{
numMap.put("JOKER",15);
numMap.put("joker",14);
numMap.put("2",13);
numMap.put("A",12);
numMap.put("K",11);
numMap.put("Q",10);
numMap.put("J",9);
numMap.put("10",8);
numMap.put("9",7);
numMap.put("8",6);
numMap.put("7",5);
numMap.put("6",4);
numMap.put("5",3);
numMap.put("4",2);
numMap.put("3",1);
}
// joker JOKER代表14,2代表13,A代表12,以此类推,0代表不是炸弹
public static int getBomp(ArrayList<String> list){
if(list.size()==2&&list.contains("joker")&& list.contains("JOKER")){
return 14;
}
if(list.size()!=4){
return 0;
}else{
String firstNum = list.get(0);
for(int i=1;i<4;i++){
if(!list.get(i).equals(firstNum)){
return 0;
}
}
return numMap.get(firstNum);
}
}
//获取顺子分数,不是顺子则是0分
public static int getShunzi(ArrayList<String> list){
if(list.size()!=5){
return 0;
}else{
if(list.contains("2")||list.contains("joker")||list.contains("JOKER")){
return 0;
}
if(list.contains("3")&&list.contains("4")&&list.contains("5")&&list.contains("6")&&list.contains("7")){
return numMap.get("3");
}else if(list.contains("4")&&list.contains("5")&&list.contains("6")&&list.contains("7")&&list.contains("8")){
return numMap.get("4");
}else if(list.contains("5")&&list.contains("6")&&list.contains("7")&&list.contains("8")&&list.contains("9")){
return numMap.get("5");
}else if(list.contains("6")&&list.contains("7")&&list.contains("8")&&list.contains("9")&&list.contains("10")){
return numMap.get("6");
}else if(list.contains("7")&&list.contains("8")&&list.contains("9")&&list.contains("10")&&list.contains("J")){
return numMap.get("7");
}else if(list.contains("8")&&list.contains("9")&&list.contains("10")&&list.contains("J")&&list.contains("Q")){
return numMap.get("8");
}else if(list.contains("9")&&list.contains("10")&&list.contains("J")&&list.contains("Q")&&list.contains("K")){
return numMap.get("9");
}else if(list.contains("10")&&list.contains("J")&&list.contains("Q")&&list.contains("K")&&list.contains("A")){
return numMap.get("10");
}else{
return 0;
}
}
}
//获取三个,两个,一个牌的分,0分代表不是纯一个数字牌
public static int getDaxiao(ArrayList<String> list){
String firstNum = list.get(0);
int n = list.size();
for(int i=1;i<n;i++){
if(!list.get(i).equals(firstNum)){
return 0;
}
}
return numMap.get(firstNum);
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
ArrayList<String> list1 = new ArrayList<>();
ArrayList<String> list2 = new ArrayList<>();
while(sc.hasNext()){
String str = sc.nextLine();
String[] strs = str.split("\\-");
String str1 = strs[0];
String str2 = strs[1];
String[] str1s = str1.split(" ");
String[] str2s = str2.split(" ");
for(int i=0;i<str1s.length;i++){
list1.add(str1s[i]);
}
for(int i=0;i<str2s.length;i++){
list2.add(str2s[i]);
}
int n1 = list1.size();
int n2 = list2.size();
int b1 = getBomp(list1);
int b2 = getBomp(list2);
if(b1>b2){
System.out.println(str1);
}else if(b1<b2){
System.out.println(str2);
}else if(n1!=n2){
System.out.println("ERROR");
}else{
int shun1 = getShunzi(list1);
int shun2 = getShunzi(list2);
if(shun1>shun2){
System.out.println(str1);
}else if(shun1<shun2){
System.out.println(str2);
}else{
int daxiao1 = getDaxiao(list1);
int daxiao2 = getDaxiao(list2);
if(daxiao1>daxiao2){
System.out.println(str1);
}else if(daxiao1<daxiao2){
System.out.println(str2);
}else{
}
}
}
}
}
}