๋ฌธ์
์ฝ๋
#include <iostream>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
string s; cin >> s;
int zero = 0, one = 0;
int flag = -1;
for (int i = 0; i < s.length(); i++) { //์ฐ์๋ ์ ๊ฐฏ์ ์ฒดํฌ
if (s[i] == '0') {
if (flag != 1) zero++;
flag = 1;
}
else if (s[i] == '1') {
if (flag != 0) one++;
flag = 0;
}
}
cout << min(zero, one);
}
'Algorithm ๐ง๐ปโ๐ป > ๋ฐฑ์ค(BOJ)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค,c++] 1504๋ฒ - ํน์ ํ ์ต๋จ ๊ฒฝ๋ก (0) | 2021.11.17 |
---|---|
[๋ฐฑ์ค,c++] 14950๋ฒ - ์ ๋ณต์ (0) | 2021.11.14 |
[๋ฐฑ์ค,c++] 14938๋ฒ - ์๊ฐ๊ทธ๋ผ์ด๋ (0) | 2021.11.14 |
[๋ฐฑ์ค,c++] 14923๋ฒ - ๋ฏธ๋ก ํ์ถ (0) | 2021.11.14 |
[๋ฐฑ์ค,c++] 14921๋ฒ - ์ฉ์ก ํฉ์ฑํ๊ธฐ (0) | 2021.11.14 |
[๋ฐฑ์ค,c++] 14920๋ฒ - 3n+1 ์์ด (0) | 2021.11.14 |
๋๊ธ