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:29:29
Task:Inversions
Sender:Oispa nutellaa
Submission time:2018-05-26 11:29:29
Status:READY
Result:ACCEPTED

Show test data

Compiler report

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

Code

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

string s;

int res = 0;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> s;
	res = s.length();
	int cres = 0;
	for (int i = 0; i < s.length(); ++i) {
		if (i%2 == 0 && s[i] != '0') cres++;
		if (i%2 == 1 && s[i] != '1') cres++; 
	}
	res = min(res, cres);
	cres = 0;
	for (int i = 0; i < s.length(); ++i) {
		if (i%2 == 1 && s[i] != '0') cres++;
		if (i%2 == 0 && s[i] != '1') cres++; 
	}
	res = min(res, cres);
	cout << res << "\n";
	return 0;
}