슈콩

[SWEA] 삼삼 트리플 게임 본문

Algorithms/SWEA

[SWEA] 삼삼 트리플 게임

shukong 2025. 11. 19. 23:47

 

 

 

[문제]

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

 

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));
		StringTokenizer st;
		int T = Integer.parseInt(br.readLine());
		for(int tc=1;tc<=T;tc++) {
			int[] R = new int[10];
			int[] G = new int[10];
			int[] B = new int[10];
			String nums = br.readLine();
			String colors = br.readLine();
			for(int i=0;i<9;i++) {
				int num = Integer.valueOf(nums.charAt(i)-'0');
				char c = colors.charAt(i);
				if(c=='R') R[num]++;
				else if(c=='G') G[num]++;
				else B[num]++;
			}
			String result = "Continue";
			int cnt = 0;
			for(int i=1;i<=7;i++) {
				while(R[i]>0 && R[i+1]>0 && R[i+2]>0) {
					R[i]--; R[i+1]--; R[i+2]--;
					cnt++;
				}
				while(B[i]>0 && B[i+1]>0 && B[i+2]>0) {
					B[i]--; B[i+1]--; B[i+2]--;
					cnt++;
				}
				while(G[i]>0 && G[i+1]>0 && G[i+2]>0) {
					G[i]--; G[i+1]--; G[i+2]--;
					cnt++;
				}
			}
			for(int i=1;i<=9;i++) {
				while(R[i]>=3) {
					cnt++;
					R[i] -= 3;
				}
				while(G[i]>=3) {
					cnt++;
					G[i] -= 3;
				}
				while(B[i]>=3) {
					cnt++;
					B[i] -= 3;
				}
			}
			if(cnt>=3) System.out.println("#"+tc+" Win");
			else System.out.println("#"+tc+" Continue");
		}
	}
}

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

[SWEA] 집합 비교  (0) 2025.11.20
[SWEA] 새샘이와 세 소수  (0) 2025.11.20
[SWEA] 세영이의 SEM력 연도  (0) 2025.11.19
[SWEA] 조 만들기  (0) 2025.11.19
[SWEA] 2016년 요일 맞추기  (0) 2025.11.19