题解 | #扑克牌大小#
扑克牌大小
https://www.nowcoder.com/practice/0a92c75f5d6b4db28fcfa3e65e5c9b3f
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNextLine()) {
String str = in.nextLine();
String firstOri = str.split("-")[0];
String secondOri = str.split("-")[1];
String input = str.replace("2", "15").replace("joker", "16").replace("JOKER",
"17").replace("J", "11").replace("Q", "12").replace("K", "13").replace("A","14");
String[] firstArray = input.split("-")[0].split("\\s+");
String[] secondArray = input.split("-")[1].split("\\s+");
String max = "";
if (firstArray.length == 1) { //1张
if (secondArray.length == 1) {
if (Integer.parseInt(firstArray[0]) > Integer.parseInt(
secondArray[0])) { //两个单张
max = firstOri;
} else {
max = secondOri;
}
} else if (secondArray.length == 2) {
if (secondArray[0].equals("16") || secondArray[0].equals("17")) { //对王
max = secondOri;
}else {
max = "ERROR";
}
} else if (secondArray.length == 4) { //四个相同牌炸弹
max = secondOri;
} else {
max = "ERROR";
}
} else if (firstArray.length == 2) { //2张
if (firstArray[0].equals("16") || firstArray[0].equals("17")) { //对王
max = firstOri;
} else if (secondArray.length == 2) {
if (secondArray[0].equals("16") || secondArray[0].equals("17")) { //对王
max = secondOri;
} else if (Integer.parseInt(firstArray[0]) > Integer.parseInt(
secondArray[0])) { //俩个对
max = firstOri;
} else {
max = secondOri;
}
} else if (secondArray.length == 4) {
max = secondOri;
} else {
max = "ERROR";
}
} else if (firstArray.length == 3) { //3张
if (secondArray.length == 2 && (secondArray[0].equals("16") ||
secondArray[0].equals("17"))) {
max = secondOri;
} else if (secondArray.length == 3) {
if (Integer.parseInt(firstArray[0]) > Integer.parseInt(secondArray[0])) {
max = firstOri;
} else {
max = secondOri;
}
} else if (secondArray.length == 4) {
max = secondOri;
} else {
max = "ERROR";
}
} else if (firstArray.length == 4) { //四张
if (secondArray.length == 2 && (secondArray[0].equals("16") ||
secondArray[0].equals("17"))) {
max = secondOri;
} else if (secondArray.length == 4) {
if (Integer.parseInt(firstArray[0]) > Integer.parseInt(secondArray[0])) {
max = firstOri;
} else {
max = secondOri;
}
} else {
max = firstOri;
}
} else if (firstArray.length == 5) {
if (secondArray.length == 4 && (secondArray[0].equals("16") ||
secondArray[0].equals("17"))) {
max = secondOri;
} else if (secondArray.length == 5) {
if (Integer.parseInt(firstArray[0]) > Integer.parseInt(secondArray[0])) {
max = firstOri;
} else {
max = secondOri;
}
} else {
max = "ERROR";
}
}
System.out.println(max);
}
}
}
#算法小白#
查看4道真题和解析