package BOJ_5635;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.time.LocalDate;
import java.util.*;
public class BOJ_5635 {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static int n;
static List<BirthInfo> birthList = new ArrayList<>();
public static void main(String[] args) throws IOException {
n = Integer.parseInt(br.readLine());
for (int i = 0; i < n; i++) {
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
String name = st.nextToken();
int day = Integer.parseInt(st.nextToken());
int month = Integer.parseInt(st.nextToken());
int year = Integer.parseInt(st.nextToken());
birthList.add(new BirthInfo(name, LocalDate.of(year, month, day)));
}
// 나이가 많은 사람이 먼저 오도록 정렬 (즉, 연도가 더 작은 사람이 앞에 오도록)
birthList.sort(Comparator.comparing(BirthInfo::getBirthDate));
// 가장 나이가 어린 사람 (최근에 태어난 사람)
System.out.println(birthList.get(n - 1).getName());
// 가장 나이가 많은 사람 (가장 오래된 생일)
System.out.println(birthList.get(0).getName());
}
// 이름과 생일을 함께 저장할 클래스
public static class BirthInfo {
private final String name;
private final LocalDate birthDate;
public BirthInfo(String name, LocalDate birthDate) {
this.name = name;
this.birthDate = birthDate;
}
public LocalDate getBirthDate() {
return birthDate;
}
public String getName() {
return name;
}
}
}
birthList.sort(Comparator.comparing(BirthInfo::getBirthDate));
birthList.sort(Comparator.comparing(BirthInfo::getBirthDate).reversed());
💡 정리하자면