質問編集履歴
14
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
-
public class ScoreManager extends ValueSortedMap< > {
|
13
|
+
public class ScoreManager extends ValueSortedMap< String, Integer > {
|
14
14
|
|
15
15
|
private final String subject;
|
16
16
|
|
13
test
CHANGED
File without changes
|
test
CHANGED
@@ -124,7 +124,95 @@
|
|
124
124
|
|
125
125
|
}
|
126
126
|
|
127
|
-
|
127
|
+
public V get(K key) {
|
128
|
+
|
129
|
+
return map.get(key);
|
130
|
+
|
131
|
+
}
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
public V remove(K key) {
|
136
|
+
|
137
|
+
V value = (key);
|
138
|
+
|
139
|
+
if ( value != null) {
|
140
|
+
|
141
|
+
List<K> keys = reverseMap.get(value);
|
142
|
+
|
143
|
+
keys.remove(key);
|
144
|
+
|
145
|
+
if (keys.isEmpty()) {
|
146
|
+
|
147
|
+
(value);
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
return value;
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
public int size() {
|
160
|
+
|
161
|
+
return map.size();
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
public Iterator<K>() {
|
168
|
+
|
169
|
+
return new Iterator<K>() {
|
170
|
+
|
171
|
+
Iterator<V> vi = reverseMap.keySet().iterator();
|
172
|
+
|
173
|
+
Iteretor<K> ki = new ArrayList<K>().iterator();
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
public boolean hasNext() {
|
178
|
+
|
179
|
+
return vi.hasNext() || ki.hasNext();
|
180
|
+
|
181
|
+
}
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
public K next() {
|
186
|
+
|
187
|
+
if (hasNext()) {
|
188
|
+
|
189
|
+
if (!ki.hasNext()) {
|
190
|
+
|
191
|
+
ki = reverseMap.get(vi.next()).iterator();
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
return ki.next();
|
196
|
+
|
197
|
+
}
|
198
|
+
|
199
|
+
throw new NoSuchElementException();
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
public void remove() {
|
206
|
+
|
207
|
+
throw new UnsupportedOperationException();
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
};
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
}
|
128
216
|
|
129
217
|
```
|
130
218
|
|
12
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,54 @@
|
|
1
1
|
基本情報技術者試験平成24年度春の問11です
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
```
|
8
|
+
|
9
|
+
import java.util.Comparator;
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
public class ScoreManager extends ValueSortedMap< > {
|
14
|
+
|
15
|
+
private final String subject;
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
public ScoreManager(String subject) {
|
20
|
+
|
21
|
+
super(new Comparator<Integer>() {
|
22
|
+
|
23
|
+
public int compare(Integer a, Integer b) {
|
24
|
+
|
25
|
+
return b.compareTo(a);
|
26
|
+
|
27
|
+
}
|
28
|
+
|
29
|
+
});
|
30
|
+
|
31
|
+
this.subject = subject;
|
32
|
+
|
33
|
+
}
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
public void print() {
|
38
|
+
|
39
|
+
System.out.println(subject + "の成績");
|
40
|
+
|
41
|
+
for (String name : this) {
|
42
|
+
|
43
|
+
System.out.printf(" %s : %d点%n", name, name, get(name));
|
44
|
+
|
45
|
+
}
|
46
|
+
|
47
|
+
}
|
48
|
+
|
49
|
+
}
|
50
|
+
|
51
|
+
```
|
2
52
|
|
3
53
|
|
4
54
|
|
11
test
CHANGED
File without changes
|
test
CHANGED
@@ -80,6 +80,52 @@
|
|
80
80
|
|
81
81
|
|
82
82
|
|
83
|
+
mainメソッド
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
```
|
88
|
+
|
89
|
+
public class ScoreManagerTester {
|
90
|
+
|
91
|
+
public static void main(String[] args) {
|
92
|
+
|
93
|
+
ScoreManager sm = new ScoreManager("数学");
|
94
|
+
|
95
|
+
try {
|
96
|
+
|
97
|
+
sm.put("FE0001", 70);
|
98
|
+
|
99
|
+
sm.put("FE0002", 90);
|
100
|
+
|
101
|
+
sm.put("FE0003", 85);
|
102
|
+
|
103
|
+
sm.put("FE0004", 95);
|
104
|
+
|
105
|
+
sm.put("FE0005", 90);
|
106
|
+
|
107
|
+
sm.put("FE0001", 85);
|
108
|
+
|
109
|
+
sm.remove("FE0004");
|
110
|
+
|
111
|
+
sm.put(null, 90)j
|
112
|
+
|
113
|
+
sm.put("FE0004", 90);
|
114
|
+
|
115
|
+
} catch (NullPointerException e) {}
|
116
|
+
|
117
|
+
sm.print();
|
118
|
+
|
119
|
+
System.out.println(sm.get("FE0004"));
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
```
|
126
|
+
|
127
|
+
|
128
|
+
|
83
129
|
質問内容
|
84
130
|
|
85
131
|
ValueSortedMapがmainメソッドから呼び出された際、最初にmapインスタンスが生成され、その後コンストラクタでreverseMapのインスタンスが生成されますよね?
|
10
test
CHANGED
File without changes
|
test
CHANGED
@@ -80,7 +80,11 @@
|
|
80
80
|
|
81
81
|
|
82
82
|
|
83
|
+
質問内容
|
84
|
+
|
83
|
-
ValueSortedMapがメ
|
85
|
+
ValueSortedMapがmainメソッドから呼び出された際、最初にmapインスタンスが生成され、その後コンストラクタでreverseMapのインスタンスが生成されますよね?
|
86
|
+
|
87
|
+
|
84
88
|
|
85
89
|
その後のputメソッド内のV old = remove(key);がどのマップに適応されるのかわかりません。
|
86
90
|
|
9
test
CHANGED
File without changes
|
test
CHANGED
@@ -60,7 +60,7 @@
|
|
60
60
|
|
61
61
|
List<K> keys = reverseMap.get(value);
|
62
62
|
|
63
|
-
if ( ) {
|
63
|
+
if (keys == null ) {
|
64
64
|
|
65
65
|
keys = new ArrayList<K>();
|
66
66
|
|
8
test
CHANGED
File without changes
|
test
CHANGED
@@ -48,7 +48,7 @@
|
|
48
48
|
|
49
49
|
public V put(K key, V value) {
|
50
50
|
|
51
|
-
if ( ) {
|
51
|
+
if ( key == null || value == null ) {
|
52
52
|
|
53
53
|
throw new NullPointerException();
|
54
54
|
|
7
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,39 +20,39 @@
|
|
20
20
|
|
21
21
|
import java.util.TreeMap;
|
22
22
|
|
23
|
+
|
24
|
+
|
23
25
|
public class ValueSortedMap<K, V> implements Iterable<K> {
|
24
26
|
|
25
|
-
Map<K, V> map = new HashMap<K, V>();
|
27
|
+
Map<K, V> map = new HashMap<K, V>();
|
26
28
|
|
27
|
-
Map<V, List<K>> reverseMap;
|
29
|
+
Map<V, List<K>> reverseMap;
|
28
30
|
|
29
31
|
|
30
32
|
|
31
|
-
public ValueSortedMap() {
|
33
|
+
public ValueSortedMap() {
|
32
34
|
|
33
|
-
reverseMap = new TreeMap<V, List<K>>();
|
35
|
+
reverseMap = new TreeMap<V, List<K>>();
|
34
|
-
|
35
|
-
}
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
> public ValueSortedMap(Comparator<? super V> c) {
|
40
|
-
|
41
|
-
>> reverseMap = new TreeMap<V,
|
42
|
-
|
43
|
-
List<K>>(c);
|
44
36
|
|
45
37
|
}
|
46
38
|
|
47
39
|
|
48
40
|
|
49
|
-
|
41
|
+
public ValueSortedMap(Comparator<? super V> c) {
|
50
42
|
|
51
|
-
|
43
|
+
reverseMap = new TreeMap<V, List<K>>(c);
|
52
44
|
|
53
|
-
|
45
|
+
}
|
54
46
|
|
47
|
+
|
48
|
+
|
49
|
+
public V put(K key, V value) {
|
50
|
+
|
55
|
-
|
51
|
+
if ( ) {
|
52
|
+
|
53
|
+
throw new NullPointerException();
|
54
|
+
|
55
|
+
}
|
56
56
|
|
57
57
|
V old = remove(key);
|
58
58
|
|
@@ -74,6 +74,8 @@
|
|
74
74
|
|
75
75
|
}
|
76
76
|
|
77
|
+
|
78
|
+
|
77
79
|
```
|
78
80
|
|
79
81
|
|
6
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
基本情報技術者試験平成24年度春の問11です
|
2
|
+
|
3
|
+
|
2
4
|
|
3
5
|
```
|
4
6
|
|
@@ -74,6 +76,8 @@
|
|
74
76
|
|
75
77
|
```
|
76
78
|
|
79
|
+
|
80
|
+
|
77
81
|
ValueSortedMapがメインメソッドで呼び出された際、最初にmapインスタンスが生成され、その後コンストラクタでreverseMapのインスタンスが生成されていますよね。
|
78
82
|
|
79
83
|
その後のputメソッド内のV old = remove(key);がどのマップに適応されるのかわかりません。
|
5
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
+
基本情報技術者試験平成24年度春の問11です
|
2
|
+
|
3
|
+
```
|
4
|
+
|
1
|
-
|
5
|
+
import java.util.ArrayList;
|
2
6
|
|
3
7
|
import java.util.Comparator;
|
4
8
|
|
@@ -14,19 +18,19 @@
|
|
14
18
|
|
15
19
|
import java.util.TreeMap;
|
16
20
|
|
17
|
-
|
21
|
+
public class ValueSortedMap<K, V> implements Iterable<K> {
|
18
22
|
|
19
|
-
|
23
|
+
Map<K, V> map = new HashMap<K, V>();
|
20
24
|
|
21
|
-
|
25
|
+
Map<V, List<K>> reverseMap;
|
22
26
|
|
23
27
|
|
24
28
|
|
25
|
-
|
29
|
+
public ValueSortedMap() {
|
26
30
|
|
27
|
-
|
31
|
+
reverseMap = new TreeMap<V, List<K>>();
|
28
32
|
|
29
|
-
|
33
|
+
}
|
30
34
|
|
31
35
|
|
32
36
|
|
@@ -68,6 +72,8 @@
|
|
68
72
|
|
69
73
|
}
|
70
74
|
|
75
|
+
```
|
76
|
+
|
71
77
|
ValueSortedMapがメインメソッドで呼び出された際、最初にmapインスタンスが生成され、その後コンストラクタでreverseMapのインスタンスが生成されていますよね。
|
72
78
|
|
73
79
|
その後のputメソッド内のV old = remove(key);がどのマップに適応されるのかわかりません。
|
4
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,33 +18,35 @@
|
|
18
18
|
|
19
19
|
> Map<K, V> map = new HashMap<K, V>();
|
20
20
|
|
21
|
-
|
21
|
+
> Map<V, List<K>> reverseMap;
|
22
22
|
|
23
23
|
|
24
24
|
|
25
|
-
public ValueSortedMap() {
|
25
|
+
> public ValueSortedMap() {
|
26
26
|
|
27
|
-
reverseMap = new TreeMap<V, List<K>>();
|
27
|
+
>> reverseMap = new TreeMap<V, List<K>>();
|
28
|
+
|
29
|
+
>> }
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
> public ValueSortedMap(Comparator<? super V> c) {
|
34
|
+
|
35
|
+
>> reverseMap = new TreeMap<V,
|
36
|
+
|
37
|
+
List<K>>(c);
|
28
38
|
|
29
39
|
}
|
30
40
|
|
31
41
|
|
32
42
|
|
33
|
-
public V
|
43
|
+
> public V put(K key, V value) {
|
34
44
|
|
35
|
-
|
45
|
+
>> if ( ) {
|
36
46
|
|
37
|
-
|
47
|
+
>> throw new ();
|
38
48
|
|
39
|
-
|
40
|
-
|
41
|
-
public V put(K key, V value) {
|
42
|
-
|
43
|
-
|
49
|
+
>> }
|
44
|
-
|
45
|
-
throw new NullPointerException();
|
46
|
-
|
47
|
-
}
|
48
50
|
|
49
51
|
V old = remove(key);
|
50
52
|
|
3
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,9 +14,9 @@
|
|
14
14
|
|
15
15
|
import java.util.TreeMap;
|
16
16
|
|
17
|
-
>public class ValueSortedMap<K, V> implements Iterable<K> {
|
17
|
+
> public class ValueSortedMap<K, V> implements Iterable<K> {
|
18
18
|
|
19
|
-
>Map<K, V> map = new HashMap<K, V>();
|
19
|
+
> Map<K, V> map = new HashMap<K, V>();
|
20
20
|
|
21
21
|
Map<V, List<K>> reverseMap;
|
22
22
|
|
2
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,9 +14,9 @@
|
|
14
14
|
|
15
15
|
import java.util.TreeMap;
|
16
16
|
|
17
|
-
>
|
17
|
+
>public class ValueSortedMap<K, V> implements Iterable<K> {
|
18
18
|
|
19
|
-
>
|
19
|
+
>Map<K, V> map = new HashMap<K, V>();
|
20
20
|
|
21
21
|
Map<V, List<K>> reverseMap;
|
22
22
|
|
1
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,11 +14,9 @@
|
|
14
14
|
|
15
15
|
import java.util.TreeMap;
|
16
16
|
|
17
|
+
>>public class ValueSortedMap<K, V> implements Iterable<K> {
|
17
18
|
|
18
|
-
|
19
|
-
public class ValueSortedMap<K, V> implements Iterable<K> {
|
20
|
-
|
21
|
-
|
19
|
+
>>Map<K, V> map = new HashMap<K, V>();
|
22
20
|
|
23
21
|
Map<V, List<K>> reverseMap;
|
24
22
|
|