티스토리 뷰
import java.io.*;
class Solution {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int T = Integer.parseInt(br.readLine());
for (int t = 1; t <= T; t++) {
int n = Integer.parseInt(br.readLine());
int[] decks = {4, 4, 4, 4, 4, 4, 4, 4, 16, 4};
int sum = 0;
for(int i = 0; i < n; i++) {
int pick = Integer.parseInt(br.readLine());
sum += pick;
decreaseDecks(pick, decks);
}
int lower = getLowerThanEqual21Cnt(sum, decks);
int greater = getGreaterThan21Cnt(sum, decks);
boolean isContinue = true;
if(greater >= lower) {
isContinue = false;
}
System.out.println("#" + t + " " + (isContinue ? "GAZUA" : "STOP"));
}
}
static void decreaseDecks(int num, int[] decks) {
decks[num - 2] -= 1;
}
static int getGreaterThan21Cnt(int nowSum, int[] decks) {
int cnt = 0;
for(int i = 0; i < decks.length; i++) {
if(decks[i] > 0) {
if(nowSum + (i + 2) > 21) {
cnt += (decks[i]);
}
}
}
return cnt;
}
static int getLowerThanEqual21Cnt(int nowSum, int[] decks) {
int cnt = 0;
for(int i = 0; i < decks.length; i++) {
if(decks[i] > 0) {
if(nowSum + (i + 2) <= 21)
cnt += (decks[i]);
}
}
return cnt;
}
}