슈콩

[SWEA] 신뢰 본문

Algorithms/SWEA

[SWEA] 신뢰

shukong 2025. 11. 15. 00:04

 

 

[문제]

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AXSVc1TqEAYDFAQT#none

 

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++) {
			st = new StringTokenizer(br.readLine());
			int n = Integer.parseInt(st.nextToken());
			Queue<String> robot = new LinkedList<>();
			Queue<Integer> orange = new LinkedList<>();
			Queue<Integer> blue = new LinkedList<>();
			for(int i=0;i<n;i++) {
				String color = st.nextToken();
				robot.offer(color);
				int x = Integer.parseInt(st.nextToken());
				if(color.equals("O")) orange.offer(x);
				else blue.offer(x);
			}
			int result = 0;
			int oP = 1;
			int bP = 1;
			while(!robot.isEmpty()) {
				boolean push = false;
				if(!orange.isEmpty()) {
					int oPos = orange.peek();
					if(oPos>oP) oP++;
					else if(oPos<oP) oP--;
					else {
						if(!push && robot.peek().equals("O")) {
							push = true;
							robot.poll();
							orange.poll();
						}
					}
				}
				if(!blue.isEmpty()) {
					int bPos = blue.peek();
					if(bPos>bP) bP++;
					else if(bPos<bP) bP--;
					else {
						if(!push && robot.peek().equals("B")) {
							push = true;
							robot.poll();
							blue.poll();
						}
					}
				}
				result++;
			}
			System.out.println("#"+tc+" "+result);
		}
	}
}

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

[SWEA] 공평한 분배 2  (0) 2025.11.15
[SWEA] 사랑의 카운슬러  (0) 2025.11.15
[SWEA] 알파벳 공부  (0) 2025.11.14
[SWEA] 힙  (0) 2025.11.14
[SWEA] 제로  (0) 2025.11.14