티스토리 뷰

Algorithm/SWEA

[JAVA] SWEA D3 / 9778. 카드 게임

heemang.dev 2024. 5. 22. 13:31

 

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

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;
    }
}
Total
Today
Yesterday
최근에 올라온 글
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30