BOJ_S5_1158
π [S5_1158] μμΈνΈμ€ λ¬Έμ
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
public class Main {
static StringTokenizer st;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
st = new StringTokenizer(br.readLine(), " ");
// μ¬λμ
int N = Integer.parseInt(st.nextToken());
// μμ
int K =Integer.parseInt(st.nextToken());
Queue<Integer> queue = new LinkedList<Integer>();
sb.append("<");
// νμ μ½μ
for(int i=1; i<N+1; i++){
queue.add(i);
}
while(!queue.isEmpty()){
for(int i=0;i<K-1;i++) {
queue.add(queue.poll());
}
if(queue.size()==1){
sb.append(queue.poll()).append(">");
}
else {
sb.append(queue.poll()).append(", ");
}
}
System.out.println(sb);
}
}
π€ λμ μκ°
μ΄ λ¬Έμ λ νλ₯Ό μ¬μ©νλ©΄ κ°λ¨νκ² ν릴 λ¬Έμ μ΄λ€.
μμ ν μλ²μ΄ μλλ©΄ poll νκ³ λ€μ add νμ¬ λ€λ‘ 보λ΄κ³
μμ ν μλ²μ΄λ©΄ poll ν΄μ£Όλ©΄ λλ€.
μ΄κ²μ νκ° λΉ λκΉμ§ μν !!