質問編集履歴
1
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -47,3 +47,119 @@
|
|
47
47
|
どのように書けば、HashMap<問題番号, <スコア, 人数>>を作ることができるのでしょうか。
|
48
48
|
|
49
49
|
教えていただきたいです。
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
↓追記です
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
```java
|
58
|
+
|
59
|
+
import java.io.*;
|
60
|
+
|
61
|
+
import java.util.HashMap;
|
62
|
+
|
63
|
+
import java.util.Map;
|
64
|
+
|
65
|
+
import java.util.Objects;
|
66
|
+
|
67
|
+
import java.util.ArrayList;
|
68
|
+
|
69
|
+
public class ScoreAnalyzer2{
|
70
|
+
|
71
|
+
public static void main(String args[]) throws IOException{ //mainメソッド
|
72
|
+
|
73
|
+
ScoreAnalyzer2 app = new ScoreAnalyzer2();
|
74
|
+
|
75
|
+
app.run(args);
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
void run(String args[]) throws IOException{ //runメソッド
|
80
|
+
|
81
|
+
HashMap<String, HashMap<String, Integer>> map = new HashMap<>(); //mapの宣言
|
82
|
+
|
83
|
+
HashMap<String, Integer> map2 = new HashMap<>(); //スコアと0
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
ArrayList<String> list = new ArrayList<>();
|
88
|
+
|
89
|
+
File file = new File(args[0]); //引数のファイルの実体を作成
|
90
|
+
|
91
|
+
BufferedReader in = new BufferedReader(new FileReader(file));
|
92
|
+
|
93
|
+
String line;
|
94
|
+
|
95
|
+
while((line = in.readLine()) != null){ //一行ずつファイルを読みこむ
|
96
|
+
|
97
|
+
String[] array = line.split(","); //1行をコンマで区切る
|
98
|
+
|
99
|
+
if(!map.containsKey(array[2]) || !map.get(array[2]).containsKey(array[4])){
|
100
|
+
|
101
|
+
HashMap<String, Integer> scores = new HashMap<>();
|
102
|
+
|
103
|
+
scores.put(array[4], 1);
|
104
|
+
|
105
|
+
map.put(array[2], scores);
|
106
|
+
|
107
|
+
System.out.println("問題番号:"+ array[2] + "スコア" + array[4] + "人数" + 1);
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
else{
|
112
|
+
|
113
|
+
Integer number_p = map.get(array[2]).get(array[4]);
|
114
|
+
|
115
|
+
number_p += 1;
|
116
|
+
|
117
|
+
map.get(array[2]).put(array[4], number_p);
|
118
|
+
|
119
|
+
System.out.println("問題番号"+array[2] + "スコア"+array[4] + "人数"+number_p);
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
```
|
128
|
+
|
129
|
+
最終的にはそれぞれの問題番号のスコアごとに割合も算出したいです。
|
130
|
+
|
131
|
+
2019/4/11 reading 1 24 10 9:30 9:31
|
132
|
+
|
133
|
+
2019/4/11 reading 1 102 10 9:30 9:40
|
134
|
+
|
135
|
+
2019/5/16 reading 5 96 8 9:03 9:09
|
136
|
+
|
137
|
+
2019/5/16 reading 5 117 10 9:03 9:07
|
138
|
+
|
139
|
+
2019/5/16 reading 5 44 10 9:03 9:09
|
140
|
+
|
141
|
+
2019/5/9 reading 4 37 8 9:02 9:09
|
142
|
+
|
143
|
+
2019/5/9 reading 4 56 6 9:02 9:07
|
144
|
+
|
145
|
+
2019/5/9 reading 4 114 8 9:02 9:10
|
146
|
+
|
147
|
+
2019/5/9 reading 4 58 8 9:03 9:10
|
148
|
+
|
149
|
+
2019/4/25 reading 3 59 8 9:00 9:12
|
150
|
+
|
151
|
+
2019/4/25 reading 3 144 6 9:03 9:11
|
152
|
+
|
153
|
+
2019/4/25 reading 3 107 8 9:07 9:13
|
154
|
+
|
155
|
+
2019/4/25 reading 3 74 2 9:11 9:14
|
156
|
+
|
157
|
+
2019/4/18 reading 2 73 2 9:00 9:13
|
158
|
+
|
159
|
+
2019/4/18 reading 2 105 8 9:00 9:10
|
160
|
+
|
161
|
+
2019/4/18 reading 2 96 6 9:00 9:07
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
データは一部抜粋です。
|