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:10:08
Task:Inversions
Sender:barely div 2.8 burgeria
Submission time:2018-05-26 11:10:08
Status:READY
Result:ACCEPTED

Show test data

Compiler report

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

Code

#include <iostream>
#include <cmath>
#include <string>

using namespace std;

typedef long long LL;

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