문제: https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV14uWl6AF0CFAYD&categoryId=AV14uWl6AF0CFAYD&categoryType=CODE
package com.company;
import java.util.Scanner;
import java.util.Queue;
import java.util.LinkedList;
public class Main {
static Scanner sc = new Scanner(System.in);
static Queue<Integer> queue = new LinkedList<Integer>();
static int n = 8;
public static int cycle(Queue<Integer> queue){
for(int i = 1; i<=5;i++){
int valid = queue.poll() - i;
if(valid <= 0){
queue.offer(0);
return -1;
}
queue.offer(valid);
}
return 1;
}
public static void solved(){
for(int i=0; i<n;i++){
queue.offer(sc.nextInt());
}
while(true){
if( -1 == cycle(queue)){
for(int i =0 ; i<n;i++){
System.out.println(queue.poll());
}
return;
}
}
}
public static void main(String args[]) {
// int testCase = sc.nextInt();
int testCase = 1;
for(int i=0; i<testCase; i++){
solved();
}
}
}