84452抽签Java版
2022/2/4 22:44:14
本文主要是介绍84452抽签Java版,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
import java.util.HashMap; import java.util.Map; import java.util.Random; public class Test { public static void main(String[] args) { Map<Integer, Map<Integer,String>> map = new HashMap(); Map<Integer,String> A = new HashMap<>(); Map<Integer,String> B = new HashMap<>(); Map<Integer,String> C = new HashMap<>(); Map<Integer,String> D = new HashMap<>(); A.put(0,"paris"); A.put(1,"crystal"); B.put(0,"milan"); B.put(1,"porto"); C.put(0,"forest"); C.put(1,"chelsea"); D.put(0,"mancity"); D.put(1,"barcelona"); map.put(0,A); map.put(1,B); map.put(2,C); map.put(3,D); Random random = new Random(); // System.out.println(random.nextInt(4)); // System.out.println(random.nextInt(4)); // System.out.println(random.nextInt(4)); // System.out.println(random.nextInt(4)); // System.out.println(random.nextInt(4)); int i = 100; int j = 100; Map m = null; int count = 0; int group = 4; //记录组信息 /** * 这个抽签是先抽小组,再抽球队(这步可以直接按名次来),同组使用group字段进行分别,只用了基础map结构,js应该可改造 */ //js可以用下面这个判断key是否存在 //ary.hasOwnProperty(key); 或 obj.hasOwnProperty(key); while (count < 8) { i = random.nextInt(1000) % 4; // 先抽取一个小组 if(i == group) { //如果同组重新抽 continue; } if(map.containsKey(i)){ //判断一下是否已经被抽取,防止异常 m = map.get(i); if (count % 2 == 0 || count == 0){ // 判断是否需要抽球队,这个也可以不用,直接按照先抽第一再抽第二就行了 j = random.nextInt(1000) % 2; }else { if (j == 1){ j--; }else { j++; } } if(m.containsKey(j)){ count++; System.out.println("第" + count + "个队伍是:" + m.get(j)); if (count % 2 != 0) { group = i; }else { group = 4; } map.get(i).remove(j); //抽完排除掉 } } } } }
这篇关于84452抽签Java版的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-15鸿蒙生态设备数量超8亿台
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了
- 2024-05-09Google Chrome驱动程序 124.0.6367.62(正式版本)去哪下载?
- 2024-05-09有没有大佬知道这种数据应该怎么抓取呀?
- 2024-05-09这种运行结果里的10.100000001,怎么能最快改成10.1?