forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path3.cpp
31 lines (25 loc) Β· 722 Bytes
/
3.cpp
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
#include <bits/stdc++.h>
using namespace std;
string str;
int count0 = 0; // μ λΆ 0μΌλ‘ λ°κΎΈλ κ²½μ°
int count1 = 0; // μ λΆ 1λ‘ λ°κΎΈλ κ²½μ°
int main(void) {
cin >> str;
// 첫 λ²μ§Έ μμμ λν΄μ μ²λ¦¬
if (str[0] == '1') {
count0 += 1;
}
else {
count1 += 1;
}
// λ λ²μ§Έ μμλΆν° λͺ¨λ μμλ₯Ό νμΈνλ©°
for (int i = 0; i < str.size() - 1; i++) {
if (str[i] != str[i + 1]) {
// λ€μ μμμ 1λ‘ λ°λλ κ²½μ°
if (str[i + 1] == '1') count0 += 1;
// λ€μ μμμ 0μΌλ‘ λ°λλ κ²½μ°
else count1 += 1;
}
}
cout << min(count0, count1) << '\n';
}