回答編集履歴
1
削除
test
CHANGED
@@ -1,135 +1 @@
|
|
1
|
-
```Java
|
2
|
-
|
3
|
-
import java.util.ArrayList;
|
4
|
-
|
5
|
-
import java.util.Collections;
|
6
|
-
|
7
|
-
import java.util.Comparator;
|
8
|
-
|
9
|
-
import java.util.HashMap;
|
10
|
-
|
11
|
-
import java.util.List;
|
12
|
-
|
13
|
-
import java.util.Map;
|
14
|
-
|
15
|
-
import java.util.Map.Entry;
|
16
|
-
|
17
|
-
import java.util.Random;
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
1
|
+
方向性が違うようなので、回答は消します
|
22
|
-
|
23
|
-
final static Integer WAIT = 50;
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
public static void main(String[] args) {
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
Random rnd = new Random();
|
36
|
-
|
37
|
-
for ( int y = 0; y < 100; y++ ) {
|
38
|
-
|
39
|
-
int r = rnd.nextInt(100) + 1;
|
40
|
-
|
41
|
-
map.put(new Integer(y),new Integer(r));
|
42
|
-
|
43
|
-
}
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
List<Map.Entry<Integer,Integer>> entries = shuffle(map);
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
System.out.println("重み付け前");
|
52
|
-
|
53
|
-
int i = 0;
|
54
|
-
|
55
|
-
for (Entry<Integer,Integer> s : entries) {
|
56
|
-
|
57
|
-
int r = rnd.nextInt(100) + 1;
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
if (i < 10) {
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
System.out.println(s.getKey() + ":" + s.getValue());
|
66
|
-
|
67
|
-
i++;
|
68
|
-
|
69
|
-
map.replace(s.getKey(), new Integer(r + WAIT.intValue()));
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
} else {
|
74
|
-
|
75
|
-
map.replace(s.getKey(), new Integer(r));
|
76
|
-
|
77
|
-
}
|
78
|
-
|
79
|
-
}
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
List<Map.Entry<Integer,Integer>> entries2 = shuffle(map);
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
System.out.println("重み付け後");
|
88
|
-
|
89
|
-
i = 0;
|
90
|
-
|
91
|
-
for (Entry<Integer,Integer> s : entries2) {
|
92
|
-
|
93
|
-
if (i < 10) {
|
94
|
-
|
95
|
-
System.out.println(s.getKey() + ":" + s.getValue());
|
96
|
-
|
97
|
-
i++;
|
98
|
-
|
99
|
-
}
|
100
|
-
|
101
|
-
}
|
102
|
-
|
103
|
-
}
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
public static List<Map.Entry<Integer,Integer>> shuffle(Map<Integer, Integer> map) {
|
108
|
-
|
109
|
-
List<Map.Entry<Integer,Integer>> entries = new ArrayList<Map.Entry<Integer,Integer>>(map.entrySet());
|
110
|
-
|
111
|
-
Collections.sort(entries, new Comparator<Map.Entry<Integer,Integer>>() {
|
112
|
-
|
113
|
-
@Override
|
114
|
-
|
115
|
-
public int compare(
|
116
|
-
|
117
|
-
Entry<Integer,Integer> entry1, Entry<Integer,Integer> entry2) {
|
118
|
-
|
119
|
-
return ((Integer)entry2.getValue()).compareTo((Integer)entry1.getValue());
|
120
|
-
|
121
|
-
}
|
122
|
-
|
123
|
-
});
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
return entries;
|
128
|
-
|
129
|
-
}
|
130
|
-
|
131
|
-
}
|
132
|
-
|
133
|
-
```
|
134
|
-
|
135
|
-
動作確認はしましたが、ちょっと自身ないっす
|