Contents

规则

 1  public static void main(String[] args) {
 2        System.out.println(ball(5000000));
 3    }
 4
 5    public static List<String> ball(int length) {
 6        int max = 33;
 7        int min = 1;
 8        List<List<StringBuilder>> list = new ArrayList<>();
 9        for (int m = 0; m < length; m++) {
10            List<StringBuilder> l = new ArrayList<>();
11            StringBuilder st = new StringBuilder();
12            for (int i = 0; i < 6; i++) {
13                int num = (int) (Math.random() * (max - min + 1) + min);
14                if (i == 0) {
15                    st.append(num);
16                } else {
17                    st.append(",").append(num);
18                }
19            }
20            int blue = (int) (Math.random() * (16 - min + 1) + min);
21            st.append(",").append(blue);
22            l.add(st);
23            list.add(l);
24        }
25        List<String> one = new ArrayList<>();
26        List<String> two = new ArrayList<>();
27        List<String> three = new ArrayList<>();
28        List<String> four = new ArrayList<>();
29        List<String> five = new ArrayList<>();
30        List<String> six = new ArrayList<>();
31        List<String> seven = new ArrayList<>();
32        for (List<StringBuilder> builderList : list) {
33            for (StringBuilder stringBuilder : builderList) {
34                String[] split = stringBuilder.toString().split(",");
35                one.add(split[0]);
36                two.add(split[1]);
37                three.add(split[2]);
38                four.add(split[3]);
39                five.add(split[4]);
40                six.add(split[5]);
41                seven.add(split[6]);
42            }
43        }
44        Map<String, Integer> onemap = count(one);
45        Map<String, Integer> twomap = count(two);
46        Map<String, Integer> threemap = count(three);
47        Map<String, Integer> fourmap = count(four);
48        Map<String, Integer> fivemap = count(five);
49        Map<String, Integer> sixmap = count(six);
50        Map<String, Integer> sevenmap = count(seven);
51        List<String> result = new ArrayList<>();
52        result.add(maxCount(onemap));
53        result.add(maxCount(twomap));
54        result.add(maxCount(threemap));
55        result.add(maxCount(fourmap));
56        result.add(maxCount(fivemap));
57        result.add(maxCount(sixmap));
58        result.add(maxCount(sevenmap));
59        return result;
60    }
61
62    private static Map<String, Integer> count(List<String> list) {
63        Map<String, Integer> map = new HashMap<>();
64        for (String s : list) {
65            if (map.containsKey(s)) {
66                int val = map.get(s);
67                map.put(s, val + 1);
68            } else {
69                map.put(s, 1);
70            }
71        }
72        return map;
73    }
74
75    private static String maxCount(Map<String, Integer> map) {
76        AtomicInteger temp = new AtomicInteger();
77        AtomicReference<String> key = new AtomicReference<>();
78        map.entrySet().stream().sorted(Collections.reverseOrder(Map.Entry.comparingByValue())).forEach(value -> {
79            if (temp.get() < value.getValue()) {
80                temp.set(value.getValue());
81                key.set(value.getKey());
82            }
83        });
84        return key.get();
85    }
86
87