Priceless
[백준] 1439번: 뒤집기 (C++) 본문

특별한 예외 처리가 필요할 줄 알았지만
생각보다 너무 쉬워서 빨리 해결할 수 있었다
개수가 적은 수를 바꿔야 하므로
값이 바뀌는 횟수를 세고 난 후 절반을 나누면 된다
// baekjoon 1439
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
// codes for fast I/O
void init(){
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
}
int main(){
init();
string input;
cin >> input;
int temp = input[0];
int n = input.length();
int switching = 0;
for(int i = 1; i < n; i++){
if (input[i] != temp) {
switching++;
}
temp = input[i];
}
cout << (switching + 1) / 2;
}
'Algorithm & Test > 백준' 카테고리의 다른 글
[백준] 16953번: A → B (C++) (0) | 2023.08.19 |
---|---|
[백준] 1783번: 병든 나이트 (C++) (0) | 2023.08.18 |
[백준] 4796번: 캠핑 (C++) (0) | 2023.08.16 |
[백준] 1427번: 소트인사이드 (C++) (0) | 2023.08.14 |
[백준] 2503번: 숫자 야구 (C++) (0) | 2023.08.13 |