题目要求
P1104题目链接
一个典型的排序题,我们将针对 year、month、day、id 四个属性进行排序,并输出对应的 name 。
使用面向对象,封装一个类,再使用sort做下处理就行啦。
AC代码(Java语言描述)import java.util.Arrays;
import java.util.Scanner;
public class Main {
private static class OIer {
String name;
Integer year;
Integer month;
Integer day;
Integer id;
OIer(String name, int year, int month, int day, int id) {
this.name = name;
this.year = year;
this.month = month;
this.day = day;
this.id = id;
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int num = Integer.parseInt(scanner.nextLine());
OIer[] oIers = new OIer[num];
for (int i = 0; i {
int year = dalao1.year.compareTo(dalao2.year);
if (year != 0) {
return year;
}
int month = dalao1.month.compareTo(dalao2.month);
if (month != 0) {
return month;
}
int day = dalao1.day.compareTo(dalao2.day);
if (day != 0) {
return day;
}
return dalao2.id.compareTo(dalao1.id);
});
for (OIer dalao : oIers) {
System.out.println(dalao.name);
}
}
}