슈콩

[SWEA] 로봇 언어 본문

Algorithms/SWEA

[SWEA] 로봇 언어

shukong 2025. 11. 18. 20:37

 

 

 

[문제]

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

 

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 disL = check(str,"L");
			int disR = check(str,"R");
			System.out.println("#"+tc+" "+Math.max(disL, disR));
		}
	}
	private static int check(String str,String d) {
		String make = str.replace("?", d);
		int result = 0;
		int max = 0;
		for(int i=0;i<make.length();i++) {
			if(make.charAt(i)=='L') result--;
			else result++;
			max = Math.max(max, Math.abs(result));
		}
		return max;
	}
}

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

[SWEA] 평범한 숫자  (0) 2025.11.18
[SWEA] 색상환  (0) 2025.11.18
[SWEA] 승률 비교하기  (0) 2025.11.18
[SWEA] 세상의 모든 팰린드롬 2  (0) 2025.11.18
[SWEA] 테네스의 특별한 소수  (0) 2025.11.18