Cod sursa(job #35716)

Utilizator thestickTudor A thestick Data 22 martie 2007 13:06:42
Problema Xor Max Scor 5
Compilator c Status done
Runda Arhiva de probleme Marime 0.5 kb
#include <stdio.h>
long n,x[100000],pmax,max,max2,pmax2,sta,sto;
void cit()
{
long i,buf,xo=0;
FILE *f;
f=fopen("xormax.in","r");
fscanf(f,"%d",&n);
x[0]=0;
for(i=0;i<n;i++)
{
fscanf(f,"%d",&buf);
xo=xo^buf;
//if(xo>max){max=xo;pmax=i;}
x[i+1]=xo;
}
}

void rez()
{
long tz,i,j;
max2=-1;
for(i=0;i<n;i++)
for(j=i;j<=n;j++)
{
tz=x[j]^x[i];
if(tz>max2){max2=tz;sta=i;sto=j;}
}
}

void tip()
{
FILE *f;
f=fopen("xormax.out","w");
fprintf(f,"%d %d %d",max2,sta+1,sto);
}

int main()
{
cit();
rez();
tip();
return 0;
}