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:19:54
Task:Inversions
Sender:Lucinda
Submission time:2018-05-26 11:19:54
Status:READY
Result:ACCEPTED

Show test data

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:19:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < mystr.size(); i++) {
                     ~~^~~~~~~~~~~~~~

Code

#include <iostream>
#include <string>
#include <stdio.h>

using namespace std;

int main() {
    /*int c;
    cout << EOF;
    while (c = getchar()) {
        cout << c;
    }*/
    string mystr;
    getline (cin, mystr);
    // cout << mystr;
    int zero = 0;
    int one = 0;
    bool even = true;
    for (int i = 0; i < mystr.size(); i++) {
        char c = mystr[i];
        if (c == '0') {
            if (even) one++;
            else zero++;
        } else {
            if (even) zero++;
            else one++;
        }
        even = !even;
    }
    if (zero < one) cout << zero;
    else cout << one;
    cout << endl;
}