본문 바로가기

3

[백준 1966] 프린터 큐 큐 문제입니다. 저번에 올렸던 프로그래머스에 있던 프린터 큐와 동일한 문제입니다. 설명은 그냥 복붙 하겠습니다. 큐에 인덱스와 우선순위를 가진 노드객체를 넣고 큐의 맨 앞을 빼오고 나머지를 이터레이터로 돌리면서 큐에 남은 노드의 우선순위를 확인합니다. (check 변수로 저장) 그리고 주석 적힌대로 현재 노드가 우선순위가 제일 높을경우 1. 현재 내가 찾을려고 했던 노드일 경우 리턴 2. 내가 찾을 노드가 아닌 경우 answer를 1 증가 시킨 후 다시 반복문 현재 노드가 우선순위가 밀릴 경우 현재 노드를 다시 큐에 붙여주는 식으로 했습니다. 2019. 4. 18.
[프로그래머스] 프린터 큐를 사용해 푸는 문제입니다 public class PrinterQueue { public static void main(String[] args) throws IOException{ int[] arr = new int[] {1, 1, 9, 1, 1, 1}; int location = 0; PrinterQueue pq = new PrinterQueue(); int result = pq.solution(arr, location); System.out.print("RESULT:"+result); } public int solution(int[] arr, int location) { int answer = 1; Queue queue = new LinkedList(); for(int i=0; i 2019. 4. 2.
[백준 11866] 조세퍼스 문제 0 큐를 사용해 문제를 해결했습니다 public class Q11866 { public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); int k = Integer.parseInt(st.nextToken()); Queue q = new LinkedList(); for(int i=1; i 2019. 4. 1.