我正在从网站上解决活动选择问题,我必须找到我可以完成的最大活动。首先,我阅读了测试用例(t)的数量,然后阅读每个活动数量(n)的数量。输入为以下格式:
2
4
Maths 16:00 18:00
ComputerScience 12:00 13:00
Physics 12:30 14:00
Chemistry 14:00 16:30
5
Geography 14:00 16:00
History 12:00 14:30
Arts 14:00 16:30
Literature 12:30 13:30
German 13:30 15:00
我写了下面给出的代码。它通过除一个测试用例。我想念什么?
import java.time.LocalTime;
import java.util.*;
class solution {
static class Subject {
String name;
LocalTime start;
LocalTime end;
public Subject(String name, String startString, String endString) {
this.name = name;
this.start = LocalTime.parse(startString);
this.end = LocalTime.parse(endString);
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt(), i;
while (t > 0) {
int count = 1,n;
LocalTime end;
n = sc.nextInt();
sc.nextLine();
if(n>0)
{
List<Subject> list = new ArrayList<Subject>();
for (i = 0; i < n; i++) {
String[] input = sc.nextLine().split(" ");
Subject subject = new Subject(input[0].trim(), input[1].trim(), input[2].trim());
list.add(subject);
}
Collections.sort(list, (s1, s2) -> s1.end.compareTo(s2.end));
end = list.get(0).end;
i = 1;
while (i < n) {
if(!list.get(i).start.isBefore(end)) {
count++;
end = list.get(i).end;
}
i++;
}
System.out.println(count);
}
else
{System.out.println("0");}
t--;
}
}
}
是否指定了有关活动确切启动时的任何内容?