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 12:22:06
Task:Inversions
Sender:Robotiimi
Submission time:2018-05-26 12:22:06
Status:READY
Result:ACCEPTED

Show test data

Compiler report

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

Code

#include <bits/stdc++.h>
#include <string>
#include <vector>

using namespace std;


int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);

string s;
cin >> s;
int n = 0;

for (int i=1; i<s.size(); i++) {
    if (s[i-1] == s[i]) {
        if (s[i] == '0') {
            s[i] = '1';
        } else {
            s[i] = '0';
        }
        n++;
    }
}
    
cout << n << "\n";
}