回答編集履歴
2
コメントがメソッドに付くように修正
test
CHANGED
@@ -44,8 +44,6 @@
|
|
44
44
|
|
45
45
|
/** 価値の高い順の Set を返す. */
|
46
46
|
|
47
|
-
static private Set<Money> descValues = null;
|
48
|
-
|
49
47
|
static Set<Money> descendingValues() {
|
50
48
|
|
51
49
|
if(descValues == null) {
|
@@ -59,6 +57,8 @@
|
|
59
57
|
return descValues;
|
60
58
|
|
61
59
|
}
|
60
|
+
|
61
|
+
static private Set<Money> descValues = null;
|
62
62
|
|
63
63
|
}
|
64
64
|
|
1
Money の大きい順 Set 周りを変更
test
CHANGED
@@ -44,13 +44,19 @@
|
|
44
44
|
|
45
45
|
/** 価値の高い順の Set を返す. */
|
46
46
|
|
47
|
-
static Set<Money>
|
47
|
+
static private Set<Money> descValues = null;
|
48
48
|
|
49
|
-
|
49
|
+
static Set<Money> descendingValues() {
|
50
50
|
|
51
|
-
|
51
|
+
if(descValues == null) {
|
52
52
|
|
53
|
+
descValues = new TreeSet<>(Comparator.comparing(Money::getValue).reversed()); //大きい順
|
54
|
+
|
55
|
+
descValues.addAll(Arrays.asList(values()));
|
56
|
+
|
57
|
+
}
|
58
|
+
|
53
|
-
return
|
59
|
+
return descValues;
|
54
60
|
|
55
61
|
}
|
56
62
|
|
@@ -61,10 +67,6 @@
|
|
61
67
|
public class Main {
|
62
68
|
|
63
69
|
public static void main(String[] args) throws IOException {
|
64
|
-
|
65
|
-
Set<Money> moneys = Money.getDescendingSet();
|
66
|
-
|
67
|
-
|
68
70
|
|
69
71
|
try (InputStreamReader reader = new InputStreamReader(System.in);
|
70
72
|
|
@@ -94,7 +96,7 @@
|
|
94
96
|
|
95
97
|
} else {
|
96
98
|
|
97
|
-
print(prepare(change
|
99
|
+
print(prepare(change));
|
98
100
|
|
99
101
|
}
|
100
102
|
|
@@ -104,13 +106,13 @@
|
|
104
106
|
|
105
107
|
}
|
106
108
|
|
107
|
-
/** change 分の紙幣/硬貨を用意
|
109
|
+
/** change 分の紙幣/硬貨を用意 */
|
108
110
|
|
109
|
-
private static Map<Money,BigDecimal> prepare(BigDecimal change
|
111
|
+
private static Map<Money,BigDecimal> prepare(BigDecimal change) {
|
110
112
|
|
111
113
|
Map<Money,BigDecimal> result = new HashMap<>();
|
112
114
|
|
113
|
-
for(Money m :
|
115
|
+
for(Money m : Money.descendingValues()) {
|
114
116
|
|
115
117
|
if(change.compareTo(m.getValue()) >= 0) {
|
116
118
|
|