SWEA_D3_1225
π [D3_1225] μνΈμμ±κΈ°
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 Solution {
static StringTokenizer st;
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
for (int T = 1; T <= 10; T++) {
int tc = Integer.parseInt(br.readLine());
sb.append("#");
sb.append(T);
sb.append(" ");
// μ
λ ₯
Queue<Integer> q = new LinkedList<Integer>();
st = new StringTokenizer(br.readLine(), " ");
for (int i = 0; i < 8; i++) {
q.offer(Integer.parseInt(st.nextToken()));
}
while(q.size()>7) {
//ν μ¬μ΄ν΄
for(int i=1; i<=5; i++) {
int x = q.poll();
x -= i;
if(x <= 0) {
for(int j =0; j<7;j++) {
sb.append(q.poll());
sb.append(" ");
}
sb.append("0");
break;
}
q.offer(x);
}
}
sb.append("\n");
}
System.out.println(sb);
}
}
π€ λμ μκ°
ν μ¬μ΄ν΄ ꡬ쑰λ₯Ό μ§λ κ²μ κ°λ¨νμ§λ§ 0μΌλ μνΈλ₯Ό λμΆνλ κ²μμ μ’ λ²λ²
μλ€.
κ·Έλ¬λ μ΄λ ΅μ§ μμ κ³Όμ μ΄μκ³ Queueλ₯Ό νμ©ν¨μΌλ‘μ¨ μ’ λ Queueμ ꡬ쑰λ₯Ό μ΄ν΄νκ² λμλ€.