Cod sursa(job #1863450)

Utilizator loghin.alexandruLoghin Alexandru loghin.alexandru Data 30 ianuarie 2017 21:56:47
Problema Xor Max Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb

#include <fstream>
#include <vector>

std::ifstream fin("xormax.in");
std::ofstream fout("xormax.out");


std::vector<int> numbers;


void read(unsigned int length)
{
	int n = 0;

	for (auto i = 0; i < length; i++)
	{
		fin >> n;
		numbers.push_back(n);
	}
}


int main()
{
	int i = 0;
	int p = -1;
	int stop = 0;
	int lungime = 0, n = 0, max = 0;
	fin >> n;
	read(n);
	if (n > 0)
	{
		max = numbers[0];
	}
	for (auto& container : numbers)
	{
		if (i>0)
		{
			p = container ^ *(&container - 1);
		}
		if (p > max)
		{
			max = p;
			*(&container - 1 ) = p;
			lungime++;
			stop = i;
		}
		else
		{
			lungime = 1;
		}
		i++;
	}
	fout << max << ' ' << stop + 2 - lungime << ' ' << stop + 1;
	return 0;
}