题目是pat的题
https://pintia.cn/problem-sets/994805260223102976/problems/994805307551629312
为什么把样例输入进去显示nullpointer
我写的一部分代码如下
package pat乙级;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.TreeSet;
public class Pat1015
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int N,L,H;
N=in.nextInt();
L=in.nextInt();
H=in.nextInt();
Student s[] = new Student[N] ;
TreeSet<Student>ts1=new TreeSet();
TreeSet<Student>ts2=new TreeSet();
TreeSet<Student>ts3=new TreeSet();
TreeSet<Student>ts4=new TreeSet();
for(int i=0;i<N;i++)
{
int id=in.nextInt();
int deScore=in.nextInt();
int caiScore=in.nextInt();
s[i].Set(id, deScore, caiScore);
if(deScore<L||caiScore<H)
{
continue;
}else if(deScore>=H&&caiScore>=H)
{
ts1.add(s[i]);
}else if(deScore>=H&&caiScore<H)
{
ts2.add(s[i]);
}else if(caiScore>=H&&deScore<H)
{
ts3.add(s[i]);
}else
{
ts4.add(s[i]);
}
}
System.out.println(ts1.size()+ts2.size()+ts3.size()+ts4.size());
}
class Student implements Comparable<Student>
{
int Id;
int DeScore;
int CaiScore;
int Sum;
public void Set(int id, int deScore, int caiScore)
{
Id = id;
DeScore = deScore;
CaiScore = caiScore;
this.Sum=deScore+caiScore;
}
public int getId()
{
return Id;
}
public void setId(int id)
{
Id = id;
}
public int getDeScore()
{
return DeScore;
}
public void setDeScore(int deScore)
{
DeScore = deScore;
}
public int getCaiScore()
{
return CaiScore;
}
public void setCaiScore(int caiScore)
{
CaiScore = caiScore;
}
public int compareTo(Student t)
{
// TODO Auto-generated method stub
if(this.Sum>t.Sum)
{
return 1;
}else if(this.Sum==t.Sum)
{
if(this.DeScore>t.DeScore)
{
return 1;
}
else if(this.DeScore==t.DeScore)
{
if(this.CaiScore>DeScore)
{
return 1;
}else if(this.CaiScore>DeScore)
{
if(this.Id>t.Id)
{
return 1;
}
}
}
}
return -1;
}
}
}