main
[백준-5635번/Java] 생일 본문
https://www.acmicpc.net/problem/5635
* ArrayList / Comparator 를 이용하여 풀었다.
import java.io.*;
import java.util.*;
public class Main {
public static class Person {
String name;
int d;
int m;
int y;
public Person(String name, int d, int m, int y) {
this.name = name;
this.d = d;
this.m = m;
this.y = y;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return this.name;
}
}
public static void main(String[] args) throws IOException {
Scanner in = new Scanner(System.in);
int N = in.nextInt();
ArrayList<Person> student = new ArrayList<Person>();
for (int i = 0; i < N; i++) {
student.add(new Person(in.next(), in.nextInt(), in.nextInt(), in.nextInt()));
}
Collections.sort(student, new Comparator<Person>() {
@Override
public int compare(Person o1, Person o2) {
if (o1.y > o2.y || o1.y == o2.y && o1.m > o2.m || o1.y == o2.y && o1.m == o2.m && o1.d > o2.d) {
return -1;
} else if (o1.y == o2.y && o1.m == o2.m && o1.d == o2.d) {
return 0;
} else {
return 1;
}
}
});
System.out.println(student.get(0));
System.out.println(student.get(student.size() - 1));
}
}
728x90
'Algorithm' 카테고리의 다른 글
[백준-1620번/Java] 나는야 포켓몬 마스터 이다솜 (0) | 2022.11.22 |
---|---|
[백준-14425번/Java] 문자열 집합 (0) | 2022.11.21 |
[백준-1436번/Java] 영화감독 숌 (0) | 2022.11.21 |
[백준-7568번/Java] 덩치 (0) | 2022.11.21 |
[백준-2231번/Java] 분해합 (0) | 2022.11.20 |
Comments