package LanQiao.C_Web.C_1975;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Scanner;
/**
* @author Huiex on 2022/3/12
*/
public class C1975 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String str = input.next();
ArrayList<Poker> list = new ArrayList();
int i = 0;
while(i < str.length()){
if (str.charAt(i) <= '9' && str.charAt(i) >= 2){
list.add(new Poker("" + str.charAt(i),str.charAt(i+1)));
i = i + 2;
}else if (str.charAt(i) == 'J') {
list.add(new Poker("J",str.charAt(i+1)));
i = i + 2;
}else if (str.charAt(i) == 'Q') {
list.add(new Poker("Q",str.charAt(i+1)));
i = i + 2;
}else if (str.charAt(i) == 'K') {
list.add(new Poker("K",str.charAt(i+1)));
i = i + 2;
}else if (str.charAt(i) == 'A') {
list.add(new Poker("A",str.charAt(i+1)));
i = i + 2;
}else{
list.add(new Poker("10", str.charAt(i+2)));
i = i + 3;
}
}
//进行比较排序
list.sort(new Comparator<Poker>(){
public int compare(Poker o1,Poker o2){
if(o2.num > o1.num) return -1;
else if (o2.num < o1.num) return 1;
else {
if(o2.color > o1.color) return -1;
else if (o2.color < o1.color) return 1;
else return 0;
}
}
});
//输出
for(Poker result : list){
System.out.print(result.num_o + result.color_o + " ");
}
}
}
class Poker{
//原本的数值 和 花色
String num_o;
char color_o;
//用于比较的 数值 和 花色
int num;
char color;
public Poker(String num,char color){
//将用于比较的数值和花色赋值
if (num == "J") this.num = 11;
else if(num == "Q") this.num = 12;
else if (num == "K") this.num = 13;
else if (num == "A") this.num = 14;
else this.num = Integer.parseInt(num);
if(color == 'd') this.color = 1;
else if (color == 'c') this.color = 2;
else if (color == 'h') this.color = 3;
else if (color == 's') this.color = 4;
//将原本的赋值
this.num_o = num;
this.color_o = color;
}
}
题目 1975: 蓝桥杯算法提高VIP-扑克排序
最新推荐文章于 2025-04-25 21:12:48 发布