백준

C++ 1439 뒤집기

안선생 2023. 2. 11. 18:28
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include <string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<vector>
using namespace std;
 
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    
    string s;
 
    cin >> s;
 
    int zero = 0 , one = 0;
 
    for (int i = 0; i < s.length(); i++)
    {
        if (s[i] != s[i + 1])
        {
            if (s[i] == '0')
                zero++;
            else
                one++;
        }
    }
 
    cout << min(zero, one);
 
}
 
 
cs

 

https://www.acmicpc.net/problem/1439

 

1439번: 뒤집기

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

www.acmicpc.net