forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3.cpp
More file actions
31 lines (25 loc) · 722 Bytes
/
3.cpp
File metadata and controls
31 lines (25 loc) · 722 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
#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';
}