-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion7.java
More file actions
44 lines (40 loc) · 2.14 KB
/
Copy pathQuestion7.java
File metadata and controls
44 lines (40 loc) · 2.14 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
36
37
38
39
40
41
42
43
44
package practice2_hashing;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
public class Question7 {
public int getTime(String time){
int H = Integer.parseInt(time.split(":")[0]);
int M = Integer.parseInt(time.split(":")[1]);
return H*60+M;
}
public String[] solution(String[] reports, int time){
//String[] answer ={};
HashMap<String, Integer> inT = new HashMap<>();
HashMap<String, Integer> sumT = new HashMap<>();
for(String x : reports){
String a = x.split(" ")[0];
String b = x.split(" ")[1];
String c = x.split(" ")[2];
if(c.equals("in")) inT.put(a, getTime(b));
else sumT.put(a, sumT.getOrDefault(a, 0) + (getTime(b) - inT.get(a)));
}
ArrayList<String> res = new ArrayList<>();
for(String name : sumT.keySet()){
if(sumT.get(name) > time) res.add(name);
}
res.sort((a, b) -> a.compareTo(b));
String[] answer = new String[res.size()];
for(int i = 0; i < res.size(); i++){
answer[i] = res.get(i);
}
return answer;
}
public static void main(String[] args){
Question7 T = new Question7();
System.out.println(Arrays.toString(T.solution(new String[]{"john 09:30 in", "daniel 10:05 in", "john 10:15 out", "luis 11:57 in", "john 12:03 in", "john 12:20 out", "luis 12:35 out", "daniel 15:05 out"}, 60)));
System.out.println(Arrays.toString(T.solution(new String[]{"bill 09:30 in", "daniel 10:00 in", "bill 11:15 out", "luis 11:57 in", "john 12:03 in", "john 12:20 out", "luis 14:35 out", "daniel 14:55 out"}, 120)));
System.out.println(Arrays.toString(T.solution(new String[]{"cody 09:14 in", "bill 09:25 in", "luis 09:40 in", "bill 10:30 out", "cody 10:35 out", "luis 10:35 out", "bill 11:15 in", "bill 11:22 out", "luis 15:30 in", "luis 15:33 out"}, 70)));
System.out.println(Arrays.toString(T.solution(new String[]{"chato 09:15 in", "emilly 10:00 in", "chato 10:15 out", "luis 10:57 in", "daniel 12:00 in", "emilly 12:20 out", "luis 11:20 out", "daniel 15:05 out"}, 60)));
}
}