-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11_03.cpp
More file actions
49 lines (39 loc) · 804 Bytes
/
11_03.cpp
File metadata and controls
49 lines (39 loc) · 804 Bytes
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
37
38
39
40
41
42
43
44
45
46
47
/***********************
* date : 2022-02-21
* topic : greedy
* feedback : 최소값 구할때, MIN()함수 쓰면 편하다!
* time : 30min
************************/
#include<iostream>
#include<string>
using namespace std;
int main_11_03()
{
string s;
// 입력받기
cin >> s;
int n = s.length();
// 연속된 구간 없애서 temp에 저장하기
string temp = "";
temp += s[0];
for(int x=1;x<n;x++)
{
if(s[x-1] != s[x]) temp += s[x];
}
// 0과 1의 갯수 세기
int zcnt = 0;
int ocnt = 0;
int t_len = temp.length();
for(int x=0;x<t_len;x++)
{
if(temp[x] == '0') zcnt++;
else ocnt++;
}
// 0과 1의 갯수 중 최소값이 최소 횟수
/*
if(zcnt < ocnt) cout << zcnt;
else cout << ocnt;
*/
cout << min(zcnt, ocnt);
return 0;
}