import java.util.*;
class Solution
{
public int solution(int []A, int []B)
{
//큰 수와 작은 수를 곱하였을 때 최솟값
Arrays.sort(A);
Arrays.sort(B);
int answer = 0;
for(int i=0; i<A.length; i++){
answer += A[i]*B[B.length-1-i];
}
return answer;
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Queue;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //선언
//입력값 받기
int num = Integer.parseInt(br.readLine());
//1~num까지의 숫자를 넣는다.
Queue<Integer> queue = new LinkedList<>();
for(int i=1; i<=num; i++){
queue.add(i);
}
while(queue.size()>1){
//맨 위의 카드를 버린다.
queue.poll();
//버린 후 남은 맨 위의 카드를 맨 밑으로 내린다.
int n = queue.poll();
queue.add(n);
}
//마지막 1장을 출력한다.
System.out.println(queue.poll());
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //선언
//입력값 받기
int num = Integer.parseInt(br.readLine());
PriorityQueue<Integer> queue = new PriorityQueue<>(
(o1, o2) -> {
int first = Math.abs(o1);
int second = Math.abs(o2);
//절댓값이 같은 경우 음수 우선 정렬
if(first==second) return o1 > o2? 1 : -1;
//절댓값 기준 정렬
else return first-second;
}
);
//정답 리스트 만들기
List<Integer> answer = new ArrayList<>();
for(int i=0; i<num; i++){
int x = Integer.parseInt(br.readLine());
//빈 배열인데 정수 x가 0이면, 0을 출력한다.
if(x==0 && queue.isEmpty()) answer.add(0);
//주어진 정수 x가 0이면, 배열에서 절댓값이 가장 작은 수를 출력하고 배열에서 제거한다.
if(x==0 && !queue.isEmpty()) answer.add(queue.poll());
//주어진 정수 x가 0이 아니면, x를 배열에 추가한다.
if(x!=0) queue.add(x);
}
for(Integer a : answer){
System.out.println(a);
}
}
}
Chapter 10. 프로세스와 스레드
Chapter 11. CPU 스케줄링
오후에 OOP 강의를 1시간 정도 들었다.
시간이 너무 빠르다.