package Deom01;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
public class Deom02_Poker {
public static void main(String[] args) {
HashMap<Integer,String> hm = new HashMap<Integer,String>();
ArrayList<Integer> list = new ArrayList<Integer>();
String[] s1 = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
String[] s2 = {"♠","♡","♧","♢"};
int index = 0;
for(String s3 : s1){
for(String s4 : s2){
hm.put(index, s4.concat(s3));
list.add(index);
index++;
}
}
list.add(index);
hm.put(index++, "小王");
list.add(index);
hm.put(index, "大王");
Collections.shuffle(list);
TreeSet<Integer> liuBei = new TreeSet<Integer>();
TreeSet<Integer> caoCao = new TreeSet<Integer>();
TreeSet<Integer> sunQuan = new TreeSet<Integer>();
TreeSet<Integer> diPai = new TreeSet<Integer>();
for(int i = 0; i < list.size();i++){
if(i >= list.size() - 3){
diPai.add(list.get(i));
}else if(i%3 == 0){
liuBei.add(list.get(i));
}else if(i%3 == 1){
caoCao.add(list.get(i));
}else if(i%3 == 2){
sunQuan.add(list.get(i));
}
}
System.out.println("刘备:");
for (Integer integer : liuBei) {
System.out.print(hm.get(integer)+" ");
}
System.out.println();
System.out.println("曹操:");
for (Integer integer : caoCao) {
System.out.print(hm.get(integer)+" ");
}
System.out.println();
System.out.println("孙权:");
for (Integer integer : sunQuan) {
System.out.print(hm.get(integer)+" ");
}
System.out.println("");
System.out.println("底牌");
for (Integer integer : diPai) {
System.out.print(hm.get(integer)+" ");
}
/*Set<Entry<Integer, String>> entrySet = hm.entrySet();
for (Entry<Integer, String> entry : entrySet) {
System.out.println(entry.getKey()+"==="+entry.getValue());
}
*/
}
}
请问这个程序可以用TreeMap改写吗?谢谢 |
|