-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_5_4_ActivityTracker
More file actions
35 lines (33 loc) · 1.02 KB
/
_5_4_ActivityTracker
File metadata and controls
35 lines (33 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.Scanner;
import java.util.TreeMap;
public class _5_4_ActivityTracker {
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
int n = input.nextInt();
input.nextLine();
TreeMap<Integer, TreeMap<String, Integer>> userInfo = new TreeMap<>();
for (int i = 0; i < n; i++) {
String[] line = input.nextLine().trim().split("[\\/ ]");
int month = Integer.parseInt(line[1]);
String user = line[3];
int distance = Integer.parseInt(line[4]);
if (!userInfo.containsKey(month)) {
userInfo.put(month, new TreeMap<String, Integer>());
}
int oldDistance = 0;
TreeMap<String,Integer> info = userInfo.get(month);
if (info.containsKey(user)) {
oldDistance = info.get(user);
}
info.put(user, oldDistance+distance);
}
for (Integer in : userInfo.keySet()) {
System.out.print(in+ ": ");
System.out.println(userInfo.get(in).toString()
.replace("{", "")
.replace("}", ")")
.replace("=", "(")
.replace(",", "),"));
}
}
}