프로그래밍 공부
BOJ/백준 25497 기술 연계마스터 임스 본문
https://www.acmicpc.net/problem/25497
조건을 잘못이해해서 빙빙 둘러갔다.
L-R 이나 S-K 사이에 L 또는 S가 들어가서 LSRK 이런식으로도 되는 거였는데 잘못 이해해서
예를 들어 R앞에 S가 나오면 break를 거는 방식으로 처음에 코딩을 했어서 삽질을 좀 했다.
#include <iostream>
#include <stack>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n; string str;
int ans = 0;
stack<char> lr, sk;
cin >> n;
cin >> str;
for(int i = 0; i < n; i++){
if(str[i] == 'L' || str[i] == 'S'){
if(str[i] == 'L') lr.push(str[i]);
else sk.push(str[i]);
}
else if(str[i] == 'R' || str[i] == 'K'){
if(str[i] == 'R'){
if(!lr.empty()){
ans++;
lr.pop();
}
else break;
}
else {
if(!sk.empty()){
ans++;
sk.pop();
}
else break;
}
}
else {
ans++;
}
}
cout << ans << '\n';
return 0;
}
'Problem Solving > Baekjoon Online Judge' 카테고리의 다른 글
BOJ/백준 2504 괄호의 값 (0) | 2024.09.09 |
---|---|
BOJ/백준 17952 과제는 끝나지 않아! (0) | 2024.08.18 |
BOJ/백준 3015 오아시스 재결합 (0) | 2024.08.10 |
BOJ/백준 22352 항체 인식 (0) | 2021.08.02 |
BOJ/백준 7568 덩치 (0) | 2021.07.21 |
Comments