-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion6.java
More file actions
57 lines (53 loc) · 2.1 KB
/
Copy pathQuestion6.java
File metadata and controls
57 lines (53 loc) · 2.1 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
45
46
47
48
49
50
51
52
53
54
55
56
57
package practice2_hashing;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
class Info implements Comparable<Info>{
public String name;
public int time;
Info(String name, int time){
this.name = name;
this.time = time;
}
@Override
public int compareTo(Info ob){
return this.time - ob.time;
}
}
public class Question6 {
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, String times){
//String[] answer ={};
ArrayList<Info> tmp = new ArrayList<>();
for(String x : reports){
String a = x.split(" ")[0];
String b = x.split(" ")[1];
tmp.add(new Info(a, getTime(b)));
}
Collections.sort(tmp);
int s = getTime(times.split(" ")[0]);
int e = getTime(times.split(" ")[1]);
ArrayList<String> res = new ArrayList<>();
for(Info ob : tmp){
if(ob.time >= s && ob.time <= e){
res.add(ob.name);
}
if(ob.time > e) break;
}
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){
Question6 T = new Question6();
System.out.println(Arrays.toString(T.solution(new String[]{"john 15:23", "daniel 09:30", "tom 07:23", "park 09:59", "luis 08:57"}, "08:33 09:45")));
System.out.println(Arrays.toString(T.solution(new String[]{"ami 12:56", "daniel 15:00", "bob 19:59", "luis 08:57", "bill 17:35", "tom 07:23", "john 15:23", "park 09:59"}, "15:01 19:59")));
System.out.println(Arrays.toString(T.solution(new String[]{"cody 14:20", "luis 10:12", "alice 15:40", "tom 15:20", "daniel 14:50"}, "14:20 15:20")));
}
}