模拟2016-2017欧冠十六强战抽签

博主作为足球迷使用JAVA编写了一个小程序来模拟欧冠抽签过程。该程序通过随机匹配不同组别的队伍来模拟实际抽签场景,并统计了每种可能对阵的概率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

作为一个狂热的足球迷,在这个马上要进行欧冠抽签的日子,博主的心情是既紧张又兴奋。不知道自己喜欢的球队会抽到哪个对手,于是用JAVA,写了个小程序来模拟欧冠抽签的过程。仅供大家娱乐娱乐!

/* * Created by Travis Zeng on 2016/12/12.
 */
public class count {

    public static int times = 0;
    static Map<String, Integer> result = new HashMap<String, Integer>();

    public static void main(String args[]) {
        java.util.List<team> teamList1 = new ArrayList<>();
        java.util.List<team> teamList2 = new ArrayList<>();
        java.util.List<team> teamList1Copy = new ArrayList<>();
        java.util.List<team> teamList2Copy = new ArrayList<>();
        List<team> possibleDraw = new ArrayList<>();
        teamList1.add(new team("Arsenal", "A", "England"));
        teamList2.add(new team("PSG", "A", "France"));
        teamList1.add(new team("Napoli", "B", "Italy"));
        teamList2.add(new team("Benfica", "B", "Portugal"));
        teamList1.add(new team("Barcelona", "C", "Spain"));
        teamList2.add(new team("ManCity", "C", "England"));
        teamList1.add(new team("ATM", "D", "Spain"));
        teamList2.add(new team("Bayern", "D", "Germany"));
        teamList1.add(new team("Monaco", "E", "France"));
        teamList2.add(new team("Leverkusen", "E", "Germany"));
        teamList1.add(new team("Dortmund", "F", "Germany"));
        teamList2.add(new team("RealMadrid", "F", "Spain"));
        teamList1.add(new team("Leichester", "G", "England"));
        teamList2.add(new team("Porto", "G", "Portugal"));
        teamList1.add(new team("Juventus", "H", "Italy"));
        teamList2.add(new team("Sevilia", "H", "Spain"));

        for (int i = 0; i < 1000000000; i++) {
            //System.out.println();
            for (team te : teamList1) {
                //System.out.println(te.getName()+" "+te.getCountry()+" "+te.getGroup());
                teamList1Copy.add(te);
            }
            for (team te : teamList2) {
                teamList2Copy.add(te);
            }
            try {
                while (teamList1Copy.size() > 0) {
                    Random random = new Random();
                    int index1 = random.nextInt(teamList1Copy.size());
                    team team1 = teamList1Copy.get(index1);
                    teamList1Copy.remove(index1);
                    for (team te : teamList2Copy) {
                        if (!(te.getGroup().equals(team1.getGroup())) && !(te.getCountry().equals(team1.getCountry()))) {
                            possibleDraw.add(te);
                        }
                    }
                    Random random1 = new Random();
                    int index2 = random1.nextInt(possibleDraw.size());
                    String draw1 = team1.getName() + " VS " + possibleDraw.get(index2).getName();
                    if (result.get(draw1) == null) {
                        result.put(draw1, 1);
                    } else {
                        int value = result.get(draw1).intValue();
                        value++;
                        result.put(draw1, new Integer(value));
                    }
                    for (team te : teamList2Copy) {
                        if (te.getName().equals(possibleDraw.get(index2).getName())) {
                            teamList2Copy.remove(te);
                            break;
                        }
                    }
                    possibleDraw = new ArrayList<team>();
                }
                times++;
            } catch (IllegalArgumentException e) {
                continue;
            }
        }
        System.out.println();
        System.out.println(times);
        Object[] keys = result.keySet().toArray();
        Arrays.sort(keys);
        for (int i = 0; i < keys.length; i++) {
            System.out.print(keys[i] + "  ");
            Float value = 1.0f * Integer.parseInt(result.get(keys[i]).toString()) / times;
            NumberFormat nf = java.text.NumberFormat.getPercentInstance();
            nf.setMaximumIntegerDigits(2);//小数点前保留几位
            nf.setMinimumFractionDigits(2);// 小数点后保留几位
            System.out.print(nf.format(value));
            for(int k=0;k<40-(keys[i].toString().length());k++){
                System.out.print(" ");
            }
            if(i%3==2){
                System.out.println();
            }
        }
    }
}

public class team {
    private String name;
    private String group;
    private String country;
    public team(String name,String group,String country){
        this.country=country;
        this.group=group;
        this.name=name;

    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getGroup() {
        return group;
    }
    public void setGroup(String group) {
        this.group = group;
    }
    public String getCountry() {
        return country;
    }
    public void setCountry(String country) {
        this.country = country;
    }
}

最后模拟的结果:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值