Code Submission Evaluation System Login

CSES - HIIT Open 2018

HIIT Open 2018

Contest start:2018-05-26 11:00:00
Contest end:2018-05-26 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard | Statistics


History
2018-05-26 11:16:16
Task:Inversions
Sender:Tefyn virallinen maajoukkue
Submission time:2018-05-26 11:16:16
Status:READY
Result:ACCEPTED

Show test data

Code

#include <bits/stdc++.h>

using namespace std;

int main(){
    string s;
    cin >> s;
    int n = s.length();
    int d1 = 0, d2 = 0;
    for(int i = 0; i < n; ++i){
        if(i%2 == 0){
            if(s[i] == '0')
                d1++;
            else
                d2++;
            
        }
        else {
         if(s[i] == '0')
                d2++;
            else
                d1++;
            
            
        }
        
    }
    cout << min(d1, d2) << endl;
    return 0;
}