카테고리 없음

[백준 1439번 / C++ / Silver V] 뒤집기

배발자 2022. 1. 16.
반응형
#include <iostream>
#include <string>
#include <algorithm>
using namespace std; 
int main() {
	string s; cin >> s; int max = 0; int cnt1 = 0; 
	int cnt2 = 0; 
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == '0') {
			while (s[i] == '0') {
				i++; 
				if (i == s.length())break; 
			}

			cnt1++; 
			i--;
		}
	}
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == '1') {
			while (s[i] == '1') {
				i++;
				if (i == s.length())break;
			}

			cnt2++;
			i--;
		}
	}
	cout << min(cnt1, cnt2);

}
반응형

댓글