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:36:38
Task:Inversions
Sender:HIIT AND RUN
Submission time:2018-05-26 11:36:38
Status:READY
Result:ACCEPTED

Show test data

Compiler report

input/code.cpp:5:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
input/code.cpp: In function 'int main()':
input/code.cpp:11:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < s.size(); ++i) {
                     ~~^~~~~~~~~~

Code

#include <bits/stdc++.h>

using namespace std;

main () {
    string s;
    cin >> s;
    
    int s1 = 0, s2 = 0;
    
    for (int i = 0; i < s.size(); ++i) {
        
        if (i % 2 == 0) {
            if (s[i] == '0')
                s2 ++;
            if (s[i] == '1')
                s1 ++;
        } else {
            if (s[i] == '0')
                s1 ++;
            if (s[i] == '1')
                s2 ++;
        }
    }
    
    cout << min(s1, s2) << endl;
}