题解 | #扑克牌大小#
扑克牌大小
https://www.nowcoder.com/practice/d290db02bacc4c40965ac31d16b1c3eb
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
String str;
String[] arr;
while (in.hasNextLine()) { // 注意 while 处理多个 case
str = in.nextLine();
arr = str.split("-");
if (arr[0].equals("joker JOKER") || arr[1].equals("joker JOKER")) {
System.out.println("joker JOKER");
break;
} else if (arr[0].split(" ").length == 4 && arr[1].split(" ").length == 4) {
if (compare(arr[0].split(" ")[0], arr[1].split(" ")[0])) {
System.out.println(arr[0]);
break;
}else{
System.out.println(arr[1]);
}
}else if(arr[0].split(" ").length == 4){
System.out.println(arr[0]);
}else if(arr[1].split(" ").length == 4){
System.out.println(arr[1]);
}else if(arr[0].split(" ").length == 3 && arr[1].split(" ").length == 3){
if(compare(arr[0].split(" ")[0], arr[1].split(" ")[0])){
System.out.println(arr[0]);
break;
}else{
System.out.println(arr[1]);
}
}else if(arr[0].split(" ").length == 5 && arr[1].split(" ").length == 5){
if(compare(arr[0].split(" ")[0], arr[1].split(" ")[0])){
System.out.println(arr[0]);
break;
}else{
System.out.println(arr[1]);
}
}else if(arr[0].split(" ").length == 2 && arr[1].split(" ").length == 2){
if(compare(arr[0].split(" ")[0], arr[1].split(" ")[0])){
System.out.println(arr[0]);
}else{
System.out.println(arr[1]);
}
}else if(arr[0].split(" ").length == 1 && arr[1].split(" ").length == 1){
if(compare(arr[0].split(" ")[0], arr[1].split(" ")[0])){
System.out.println(arr[0]);
}else{
System.out.println(arr[1]);
}
}else{
System.out.println("ERROR");
}
}
}
public static boolean compare(String ch1, String ch2) {
if(ch1.equals("JOKER")){
return true;
}
if(ch2.equals("JOKER")){
return false;
}
if(ch1.equals("joker")){
return true;
}
if(ch2.equals("joker")){
return false;
}
if (ch1.equals("2")) {
return true;
}
if (ch2.equals("2")) {
return false;
}
if (ch1.equals("A")) {
return true;
}
if (ch2.equals("A")) {
return false;
}
if (ch1.length() == 1&&ch1.charAt(0) >= 'J' && ch1.charAt(0) <= 'K') {
if (ch2.length() == 1&& ch2.charAt(0) >= 'J' && ch2.charAt(0) <= 'K') {
if (ch1.charAt(0) > ch2.charAt(0)) {
return true;
} else {
return false;
}
} else {
return true;
}
}
if (ch2.length() == 1&&ch2.charAt(0) >= 'J' && ch2.charAt(0) <= 'K') {
if (ch1.length() == 1&& ch1.charAt(0) >= 'J' && ch1.charAt(0) <= 'K') {
if (ch1.charAt(0) > ch2.charAt(0)) {
return true;
} else {
return false;
}
} else {
return false;
}
}
return Integer.parseInt(ch1) > Integer.parseInt(ch2);
}
}
网易游戏公司福利 599人发布