A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© ouyzm 中级黑马   /  2016-10-17 00:04  /  860 人查看  /  6 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Set;
import java.util.TreeMap;


public class pukepai {

        /**
         * 模拟斗地主洗牌和发牌并对牌进行排序的代码实现
         */
        public static void main(String[] args) {
                String[] color ={"黑桃","梅花","方块","红桃"};
                String[] pai = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
                HashMap<Integer,String> hm = new HashMap<>();
                int i = 0;
                for (String st : pai) {
                        for (String str : color) {
                        hm.put(i++, str.concat(st))        ;
                        }
                }
                hm.put(52, "小王");
                hm.put(53, "大王");
                System.out.println(hm);
               
                TreeMap<Integer,String> ouy = new TreeMap<>();
                TreeMap<Integer,String> gaojin = new TreeMap<>();
                TreeMap<Integer,String> zhouxingchi = new TreeMap<>();
                TreeMap<Integer,String> dipai = new TreeMap<>();
                ArrayList <Integer> al = new ArrayList<>();
                  Set<Integer> keySet = hm.keySet();
                  for (Integer integer : keySet) {
                        al.add(integer);
                }
                  System.out.println(al);
                  System.out.println("-----------");
                  Collections.shuffle(al);
                System.out.println(al);
               
                for (int i1 =0;i1<al.size();i1++) {
                       
                        if(i1>=al.size()-3){
                                dipai.put(i1,hm.get(al.get(i1)));
                        }
                        if(i1%3==0){
                                ouy.put(i1,hm.get(al.get(i1)));
                        }if(i1%3==1){
                                gaojin.put(i1, hm.get(al.get(i1)));
                        }else{
                                zhouxingchi.put(i1, hm.get(al.get(i1)));
                        }
                }
                System.out.println(ouy);
                System.out.println("-----");
                System.out.println(gaojin);
                System.out.println("-----");
                System.out.println(zhouxingchi);
                System.out.println("-----");
                System.out.println(dipai);
        }

}


6 个回复

倒序浏览
回复 使用道具 举报
回复 使用道具 举报
不错,继续加油
回复 使用道具 举报
回复 使用道具 举报
6666,赞一个
回复 使用道具 举报
ouyzm 中级黑马 2016-10-18 01:00:39
7#
谢谢哈哈
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马