[백준] 1439번 Silver 5 뒤집기, C++ 코드
·
Algorithm/BOJ
단순히 이전 값과 비교하여 다르면 +1을 하는 구조로 풀 수 있다.마지막에는 1을 뒤집는데 드는 비용, 0을 뒤집는데 드는 비용 중 최솟값을 출력하면 된다. #include #define endl "\n"using namespace std;int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s; cin >> s; int zero_cnt = 0, one_cnt = 0; char before = '\0'; for (char c : s) { if (before != c) { if (c == '0') { zero_cnt++; } else ..