백준 1158번
제목 : 요세푸스 문제
난이도 실버5
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
public class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
String [] b = input.readLine().split(" ");
int n = Integer.parseInt(b[0]);
int r = Integer.parseInt(b[1]);
LinkedList<Integer> yo = new LinkedList<>();
int index = 0;
for(int i = 1; i<=n; i++){
yo.add(i);
}
System.out.print("<");
while(!yo.isEmpty()){
for(int i =0; i<r; i++){
if(i==r-1){
int a =yo.remove(index);
if(yo.size()==0){
System.out.print(a);
}
else System.out.print(a + ", ");
}
else{
yo.add(yo.remove());
}
}
}
System.out.print(">");
}
}