Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

21.03.10 - [BOJ] 2164. 카드 2 #27

Closed
suhyunsim opened this issue Mar 9, 2021 · 0 comments
Closed

21.03.10 - [BOJ] 2164. 카드 2 #27

suhyunsim opened this issue Mar 9, 2021 · 0 comments
Assignees
Labels
성공 맞은 문제 실버 BOJ - 실버 Queue

Comments

@suhyunsim
Copy link
Owner

suhyunsim commented Mar 9, 2021

문제

핵심 아이디어

  • 단순히 카드들을 큐에 넣고 빼다가 마지막에 남은 한 장을 구하면 되는 문제

어려운 점, 실수

풀이

package main.java.com.poogle.BOJ.Q2164;

import java.io.*;
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));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        int n = Integer.parseInt(br.readLine());
        Queue<Integer> cards = new LinkedList<>();
        for (int i = 1; i <= n; i++){
            cards.offer(i);
        }
        int i = 1;
        while (cards.size() != 1) {
            if (i % 2 == 1) {
                cards.poll();
            } else {
                cards.offer(cards.poll());
            }
            i++;
        }
        bw.write(cards.peek() + "\n");
        bw.flush();
        br.close();
        bw.close();
    }
}
@suhyunsim suhyunsim added 실버 BOJ - 실버 Queue labels Mar 9, 2021
@suhyunsim suhyunsim added this to the 3월 2주 차 milestone Mar 9, 2021
@suhyunsim suhyunsim self-assigned this Mar 9, 2021
@suhyunsim suhyunsim added the 성공 맞은 문제 label Mar 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
성공 맞은 문제 실버 BOJ - 실버 Queue
Projects
None yet
Development

No branches or pull requests

1 participant