Algorythms
백준 2164번 자바 풀이
by 준형코딩
2022. 3. 1.
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class baekjoon2164 {
public static void main(String[]args){
Queue<Integer> queue = new LinkedList<>();
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
for(int i = 1 ; i<= a; i ++){
queue.add(i);
}
int c1 =0;
int c2 =0;
boolean check =true;
if(a==1){
System.out.println(1);
}
while(check==true&&a!=1 ){
try{
c1 = queue.poll();
}catch(Exception e){
System.out.println(c1);
break;
}
try{
c2 = queue.poll();
queue.add(c2);
}catch(Exception e){
System.out.println(c2);
break;
}
}
}
}