Cod sursa(job #1706808)

Utilizator MotoAMotoi Alexandru MotoA Data 23 mai 2016 12:21:15
Problema Xor Max Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("xormax.in");
ofstream g("xormax.out");
int main()
{
 int n, smax = 0, k, p, x[2001] = {0}, s, in , stop;
    f >> n;
    for(k = 1; k <= n; k++)
        {
        f >> a;
        x[k] = x[k - 1] ^ a;
        }
    for(k = 1; k <= n - 1; k++)
       for(p=k;p<=n;p++)
       {s=x[p]^x[k-1];
        if(s>smax){smax=s;in=k;stop=p;}
         else if(s==smax &&p<stop){smax=s;in=k;stop=p;}
       }
    g<<smax<<' '<<in<<' '<<stop;
    return 0;
}