반응형

www.acmicpc.net/problem/1439

 

1439번: 뒤집기

다솜이는 0과 1로만 이루어진 문자열 S를 가지고 있다. 다솜이는 이 문자열 S에 있는 모든 숫자를 전부 같게 만들려고 한다. 다솜이가 할 수 있는 행동은 S에서 연속된 하나 이상의 숫자를 잡고 모

www.acmicpc.net

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <algorithm>
using namespace std;
int cnt0, cnt1;
int main() {
    string str;
    cin >> str;
    char cur = str[0];
    if (cur == '0')
        cnt0++;
    else
        cnt1++;
    for (char c : str) {
        if (cur != c) {
            if (c == '0')
                cnt0++;
            else
                cnt1++;
            cur = c;
        }
    }
    cout << min(cnt0, cnt1);
}
cs
반응형

'백준 > 그리디' 카테고리의 다른 글

백준 16953  (0) 2021.02.05
백준 2847  (0) 2021.02.05
백준 1449  (0) 2021.02.05
백준 2437  (0) 2021.02.05
백준 1715  (0) 2021.02.05

+ Recent posts