Cod sursa(job #1585912)

Utilizator AttyyKucsvan Attila Attyy Data 31 ianuarie 2016 16:23:11
Problema Xor Max Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <stdio.h>
#include <stdlib.h>

int main()
{
    freopen("xormax.in", "r", stdin);
    freopen("xormax.out", "w", stdout);
    unsigned long int n, i, j, k, xorr, *ma, maxi = 0, start, endd;
    scanf("%d", &n);
    ma = (unsigned long int*) malloc (n* sizeof(unsigned long int));
    for(i = 0; i < n; ++i)
    {
        scanf("%d", ma+i);
    }
    for(i = 0; i < n; ++i)
    {
        for(j = 0; j < i; ++j)
        {
            xorr = ma[j];
            for(k = j+1; k <= i; ++k)
            {
                xorr ^= ma[k];
            }
            if(xorr > maxi)
            {
                maxi = xorr;
                start = j;
                endd = i;
            }
        }
    }
    printf("%lu %lu %lu", maxi, start+1, endd+1);
    return 0;
}