BackJoon Algorithm - Java

문제

풀이
- 우선순위 큐의 대한 개념을 알기에 좋은 문제였던거 같다.
- 우선순위 큐는 디폴트가 작은수부터 나오기 때문에 큰수부터 출력하도록 Collections.reverseOrder()을 넣었다.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
public class Back_2075 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
int n = Integer.parseInt(br.readLine());
PriorityQueue<Integer> pq = new PriorityQueue<Integer>(Collections.reverseOrder());
for (int i = 0; i < n; i++) {
st = new StringTokenizer(br.readLine()," ");
for (int j = 0; j < n; j++) {
int num = Integer.parseInt(st.nextToken());
pq.offer(num);
}
}
for (int i = 0; i < n - 1; i++) {
pq.poll();
}
System.out.println(pq.poll());
}
}
댓글남기기