슈콩

[SWEA] 영준이의 카드 카운팅 본문

Algorithms/SWEA

[SWEA] 영준이의 카드 카운팅

shukong 2025. 11. 15. 21:37

 

 

[문제]

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWIsY84KEPMDFAWN

 

SW Expert Academy

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

swexpertacademy.com

 

 

 

[소스 코드]

import java.io.*;
import java.util.*;
public class Solution {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int T = Integer.parseInt(br.readLine());
		for(int tc=1;tc<=T;tc++) {
			String str = br.readLine();
			int s,d,h,c;
			s = d = h = c = 13;
			boolean[] sCnt = new boolean[14];
			boolean[] dCnt = new boolean[14];
			boolean[] hCnt = new boolean[14];
			boolean[] cCnt = new boolean[14];
			boolean check = true;
			out:
			for(int i=0;i<=str.length()-3;i+=3) {
				String info = str.substring(i,i+3);
				char shape = info.charAt(0);
				int cnt = Integer.valueOf(info.substring(1,3));
				if(shape=='S') {
					if(sCnt[cnt]) {
						check = false;
						break out;
					}
					s--;
					sCnt[cnt] = true;
				}
				if(shape=='D') {
					if(dCnt[cnt]) {
						check = false;
						break out;
					}
					d--;
					dCnt[cnt] = true;
				}
				if(shape=='H') {
					if(hCnt[cnt]) {
						check = false;
						break out;
					}
					h--;
					hCnt[cnt] = true;
				}
				if(shape=='C') {
					if(cCnt[cnt]) {
						check = false;
						break out;
					}
					c--;
					cCnt[cnt] = true;
				}
			}
			if(!check) {
				System.out.println("#"+tc+" ERROR");
			}
			else {
				System.out.println("#"+tc+" "+s+" "+d+" "+h+" "+c);
			}
		}
	}
}

'Algorithms > SWEA' 카테고리의 다른 글

[SWEA] 공과 잡초  (0) 2025.11.15
[SWEA] 코딩 토너먼트1  (0) 2025.11.15
[SWEA] 민정이와 광직이의 알파벳 공부  (0) 2025.11.15
[SWEA] 이진수 표현  (0) 2025.11.15
[SWEA] 체스판 위의 룩 배치  (0) 2025.11.15