반응형
풀이
- 2차원 배열 정렬 문제라서 한 번 풀어봄.
- 다만 처음엔 조건식에 생일인 문자열 타입의 정수를 그대로 비교해서
- 정렬을 했는데, 출력해보니 이상하게 정렬되어서
- 뭐지하고 다시 정수로 형변환 후 시도 해보니
- 원하는 대로 잘 되었다.
import java.io.*;
import java.util.*;
import java.util.Comparator;
public class _5635 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
int N = Integer.parseInt(br.readLine());
Object[][] li = new Object[N][4];
for (int i=0; i<N; i++) {
st = new StringTokenizer(br.readLine());
li[i][0] = st.nextToken();
for (int j=3; j>0; j--) li[i][j] = Integer.parseInt(st.nextToken());
}
Arrays.sort(li, new Comparator<Object[]>() {
public int compare(Object[] o1, Object[] o2) {
if ((int)o1[1]!=(int)o2[1]) return Integer.compare((int)o1[1],(int)o2[1]);
else if ((int)o1[2]!=(int)o2[2]) return Integer.compare((int)o1[2],(int)o2[2]);
else return Integer.compare((int)o1[3],(int)o2[3]);
}
});
System.out.println(li[N-1][0]);
System.out.println(li[0][0]);
}
}
'알고리즘' 카테고리의 다른 글
[백준, 자바, 17478번] 재귀함수가 뭔가요? (0) | 2024.10.23 |
---|---|
[백준, 자바, 2583번] 영역 구하기 (1) | 2024.10.22 |
[백준, 자바, 2003번] 수들의 합 2 (0) | 2024.10.14 |
[백준, 자바, 11728번] 스피카 (1) | 2024.10.14 |
[백준, 자바, 15723번] n단 논법 (2) | 2024.10.14 |