• 洗牌算法


    package demo_map;
    
    import java.util.*;
    
    public class Doudizhu_map {
        public static void main(String[] args) {
            List<String> list1=List.of("color joker","black joker");
            List<String> list01=List.of("♣","♠","♥","♦");
            List<String> list02=List.of("2","A","K","Q","J","10","9","8","7","6","5","4","3");
    
    
    
    
            HashMap<Integer,String> h1=new HashMap<>();
            int count=0;
            h1.put(count++,"color joker");
            h1.put(count++,"black joker");
            for (String numbers:list02) {
                for (String color:list01) {
                    String card=color+numbers;
                    h1.put(count++,card);
                }
    
            }
            Set<Integer> set=h1.keySet();
            List<Integer> numList=new ArrayList<Integer>();
            numList.addAll(set);
            System.out.println(numList.toString());
            Collections.shuffle(numList);
    
            //zhuangpai
    
            ArrayList<Integer> gamer1=new ArrayList<>();
            ArrayList<Integer> gamer2=new ArrayList<>();
            ArrayList<Integer> gamer3=new ArrayList<>();
            ArrayList<Integer> rest=new ArrayList<>();
    
    
            for(int key=0;key<numList.size();key++){
    
                if(key>50){
    
                    rest.add(numList.get(key));
                }else if(key%3==0){
                    gamer1.add(numList.get(key));
                }else if(key%3==1){
                    gamer2.add(numList.get(key));
                }else if (key%3==2){
                    gamer3.add(numList.get(key));
                }
            }
            Collections.sort(rest);
    
            Collections.sort(gamer1);
            System.out.println(gamer1);
            Collections.sort(gamer2);
            Collections.sort(gamer3);
    
            LinkedHashMap<Integer,String> restm=new LinkedHashMap<>();
            for (int i = 0; i <rest.size() ; i++) {
                restm.put(rest.get(i),h1.get(rest.get(i)));
            }
    
            LinkedHashMap<Integer,String> gamer1m=new LinkedHashMap<>();
            for (int i = 0; i <gamer1.size(); i++) {
                gamer1m.put(gamer1.get(i),h1.get(gamer1.get(i)));
            }
            LinkedHashMap<Integer,String> gamer2m=new LinkedHashMap<>();
            for (int i = 0; i <gamer2.size() ; i++) {
                gamer2m.put(gamer2.get(i),h1.get(gamer2.get(i)));
            }
            LinkedHashMap<Integer,String> gamer3m=new LinkedHashMap<>();
            for (int i = 0; i <gamer3.size() ; i++) {
                gamer3m.put(gamer3.get(i),h1.get(gamer3.get(i)));
            }
            System.out.println(restm.toString());
            System.out.println(gamer1m.toString());
            System.out.println(gamer2m.toString());
            System.out.println(gamer3m.toString());
            //排序
    
    
    
    
        }
    }
  • 相关阅读:
    Catalan数(卡特兰数)
    100个乘客登机问题
    [设计模式]抽象工厂模式
    栈-队和队-栈
    java实现字符串反转
    java实现字符串按词反转
    windows上安装maven及eclipse中配置maven
    Windows 10 安装 Docker
    Win7操作系统安装IE10提示“安装前需要更新与安装程序版本”
    解决Jenkins权限配置错误,导致登录时出现没有Overall/read权限
  • 原文地址:https://www.cnblogs.com/resort-033/p/13082457.html
Copyright © 2020-2023  润新知