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:09:34
Task:Inversions
Sender:DualCore
Submission time:2018-05-26 12:09:34
Status:READY
Result:ACCEPTED

Show test data

Compiler report

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

Code

/*
 * main.cpp
 *
 *  Created on: May 26, 2018
 *      Author: guest132
 */

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

int main()
{
	std::string input;
	std::getline(std::cin, input);


	int count1 = 0;
	for (int i = 0; i < input.length() - 1; ++i)
	{
			int L = 0;
			int R = input[i] - '0';
			if (L != R)
				++count1;
			++i;
			L = 1;
			R = input[i] - '0';
			if (L != R)
				++count1;
	}
	if (input.length() % 2 == 1)
	{
		int L = 0;
		int R = input[input.length() - 1] - '0';
		if (L != R)
			++count1;
	}

	int count2 = 0;
	for (int i = 0; i < input.length() - 1; ++i)
	{
			int L = 1;
			int R = input[i] - '0';
			if (L != R)
				++count2;
			++i;
			L = 0;
			R = input[i] - '0';
			if (L != R)
				++count2;
	}
	if (input.length() % 2 == 1)
	{
		int L = 1;
		int R = input[input.length() - 1] - '0';
		if (L != R)
			++count2;
	}

	std::cout << std::min(count1, count2);
}