Created
February 10, 2022 13:10
-
-
Save sedin2/7d3462f21992c49b4a7d5ab4f16e2b2f to your computer and use it in GitHub Desktop.
BJ_1158_요세푸스
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ssafy.im; | |
import java.io.BufferedReader; | |
import java.io.InputStreamReader; | |
import java.io.StringReader; | |
import java.util.LinkedList; | |
import java.util.Queue; | |
import java.util.StringTokenizer; | |
public class Main { | |
static String input = "7 3"; | |
public static void main(String[] args) throws Exception { | |
// TODO Auto-generated method stub | |
// BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
BufferedReader br = new BufferedReader(new StringReader(input)); | |
StringTokenizer st = new StringTokenizer(br.readLine()); | |
StringBuilder sb = new StringBuilder(); | |
sb.append("<"); | |
int N = Integer.parseInt(st.nextToken()); | |
int K = Integer.parseInt(st.nextToken()); | |
Queue<Integer> people = new LinkedList<Integer>(); | |
for (int i = 1; i <= N; i++) { | |
people.offer(i); | |
} | |
while (people.size() != 1) { | |
for (int i = 0; i < K - 1; i++) { | |
people.offer(people.poll()); | |
} | |
sb.append(people.poll() + ", "); | |
} | |
sb.append(people.poll()); | |
sb.append(">"); | |
System.out.println(sb); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
BJ_1158_요세푸스