OJ
                
              [BOJ] 25497 기술 연계마스터 임스 (JAVA)
                P3PP4
                 2023. 7. 4. 10:00
              
                          
            https://www.acmicpc.net/problem/25497
25497번: 기술 연계마스터 임스
$1$, $2$, $S$ - $K$, $2$로 스킬을 성공적으로 총 4번 사용했다.
www.acmicpc.net
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
	
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        char[] input = br.readLine().toCharArray();
        int S = 0;
        int L = 0;
        int cnt = 0;
        for (int i = 0; i < N; i++) {
            if (input[i] == 'S') S++;
            else if (input[i] == 'K') {
                if (0 < S) {
                    cnt++;
                    S--;
                }
                else break;
            }
            else if (input[i] == 'L') L++;
            else if (input[i] == 'R') {
                if (0 < L) {
                    cnt++;
                    L--;
                }
                else break;
            }
            else cnt++;
        }
        System.out.print(cnt);
    }
}