문제) 백준 - Greedy - 블로그2
https://www.acmicpc.net/problem/20365
20365번: 블로그2
neighbor 블로그를 운영하는 일우는 매일 아침 풀고 싶은 문제를 미리 정해놓고 글을 올린다. 그리고 매일 밤 각각의 문제에 대하여, 해결한 경우 파란색, 해결하지 못한 경우 빨간색으로 칠한
www.acmicpc.net
주어진 문자열의 연속된 R, B를 하나로 줄인 후, 최소로 사용된 것을 선택하면 됩니다.
C++ 소스코드)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define endl "\n" | |
#define ll long long | |
#define INF 987654321 | |
#define MAX 31 | |
using namespace std; | |
int N; | |
string s; | |
signed main() { | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); cout.tie(0); | |
cin >> N >> s; | |
s.erase(unique(s.begin(), s.end()), s.end()); | |
int cnt_BB = 0, cnt_RR = 0; | |
for (int i = 0; i < s.size(); ++i) | |
if (s[i] == 'B') { | |
cnt_BB++; | |
} | |
else { | |
cnt_RR++; | |
} | |
cout << min(1 + cnt_RR, 1 + cnt_BB); | |
return 0; | |
} |
반응형
'PS(Problem Solving) > 백준_BOJ' 카테고리의 다른 글
[백준] 19942번 - 다이어트 (C++) 문제 및 풀이 (0) | 2022.01.16 |
---|---|
[백준] 2629번 - 양팔저울 (C++) 문제 및 풀이 (0) | 2022.01.15 |
[백준] 16432번 - 떡장수와 호랑이 (C++) 문제 및 풀이 (0) | 2022.01.13 |
[백준] 15658번 - 연산자 끼워넣기 (2) (C++) 문제 및 풀이 (0) | 2022.01.13 |
[백준] 10798번 - 세로읽기 (C++) 문제 및 풀이 (0) | 2022.01.13 |
댓글