package com.zr;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
public class card {
public card() {
}
private static <E> void swap(List<E> list, int index1, int index2) {
E e = list.get(index1);
list.set(index1, list.get(index2));
list.set(index2, e);
}
private static ArrayList<String> paix(ArrayList<String> x) {
ArrayList<Integer> card = new ArrayList();
int j = true;
int i;
for(i = 0; i < x.size(); ++i) {
int j;
if (((String)x.get(i)).equals("大\ud83c\udccf")) {
j = 172;
} else if (((String)x.get(i)).equals("小\ud83c\udccf")) {
j = 171;
} else {
if (((String)x.get(i)).substring(1).equals("A")) {
j = 140;
} else if (((String)x.get(i)).substring(1).equals("2")) {
j = 150;
} else if (((String)x.get(i)).substring(1).equals("J")) {
j = 110;
} else if (((String)x.get(i)).substring(1).equals("Q")) {
j = 120;
} else if (((String)x.get(i)).substring(1).equals("K")) {
j = 130;
} else {
j = Integer.parseInt(((String)x.get(i)).substring(1)) * 10;
}
if (((String)x.get(i)).substring(0, 1).equals("♥")) {
j += 4;
} else if (((String)x.get(i)).substring(0, 1).equals("♦")) {
j += 3;
} else if (((String)x.get(i)).substring(0, 1).equals("♠")) {
j += 2;
} else if (((String)x.get(i)).substring(0, 1).equals("♣")) {
++j;
}
}
card.add(j);
}
for(i = x.size(); i > 1; --i) {
for(int a = 0; a < i - 1; ++a) {
if ((Integer)card.get(a) < (Integer)card.get(a + 1)) {
swap(card, a, a + 1);
swap(x, a, a + 1);
}
}
}
return x;
}
public static void main(String[] args) {
List<String> pokes = new ArrayList();
List<String> colors = new ArrayList();
List<String> numbers = new ArrayList();
colors.add("♥");
colors.add("♠");
colors.add("♦");
colors.add("♣");
numbers.add("A");
for(int i = 2; i <= 10; ++i) {
numbers.add(i + "");
}
numbers.add("J");
numbers.add("Q");
numbers.add("K");
Iterator var10 = colors.iterator();
while(var10.hasNext()) {
String c = (String)var10.next();
Iterator var6 = numbers.iterator();
while(var6.hasNext()) {
String n = (String)var6.next();
String pai = c + n;
pokes.add(pai);
}
}
pokes.add("大\ud83c\udccf");
pokes.add("小\ud83c\udccf");
System.out.println("生成纸牌后:");
System.out.println(pokes);
System.out.println("\n随机打乱纸牌后:");
Collections.shuffle(pokes);
System.out.println(pokes);
ArrayList<String> card1 = new ArrayList();
ArrayList<String> card2 = new ArrayList();
ArrayList<String> card3 = new ArrayList();
ArrayList<String> card4 = new ArrayList();
for(int i = 0; i < pokes.size(); ++i) {
String pai = (String)pokes.get(i);
if (i >= 51) {
card4.add(pai);
} else if (i % 3 == 0) {
card1.add(pai);
} else if (i % 3 == 1) {
card2.add(pai);
} else {
card3.add(pai);
}
}
System.out.println("\n随机分配纸牌后:");
System.out.println(card1);
System.out.println(card2);
System.out.println(card3);
System.out.println(card4);
card1 = paix(card1);
card2 = paix(card2);
card3 = paix(card3);
card4 = paix(card4);
System.out.println("\n整理排序纸牌后:");
System.out.println(card1);
System.out.println(card2);
System.out.println(card3);
System.out.println(card4);
}
}
JAVA 0624作业
最新推荐文章于 2024-08-19 16:01:20 发布