Cod sursa(job #561543)

Utilizator vgabi94Vaduva Gabriel vgabi94 Data 20 martie 2011 18:55:36
Problema Xor Max Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <fstream>
#include <queue>
using namespace std;

fstream fin("xormax.in", ios::in);
fstream fout("xormax.out", ios::out);

struct Max {int start; int stop; int value;} maxim, temp;

int main()
{
	int n; queue<Max> max, nr;
	fin >> n >> temp.value; temp.start = 1; temp.stop = 1; maxim = temp;
	max.push(temp); nr.push(temp); 
	while(!fin.eof())
	{
		fin >> temp.value; temp.stop++; temp.start++; 
		nr.push(temp);
		if((temp.value ^ nr.front().value) > maxim.value)
		{
			maxim.value = temp.value ^ nr.front().value;
			maxim.start = nr.front().start; maxim.stop = temp.stop;
		}
		nr.pop(); 
		if((temp.value ^ max.front().value) > maxim.value)
		{
			maxim.value = temp.value ^ max.front().value;
			maxim.start = max.front().start; maxim.stop = temp.stop;
			max.push(maxim);
			max.pop(); 
		}
	}
	fout << maxim.value << " " << maxim.start << " " << maxim.stop;
	return 0;
}