Tuesday, January 15, 2013

Onotole needs your help SPOJ



7742. Onotole needs your help

Problem code: OLOLO






#include<stdio.h>
int main()
{
    int n,i;
    scanf("%d",&n);
    long long int arr[n];
    for(i=0;i<n;i++)
        scanf("%lld",&arr[i]);
    long long int a,ans;
    a=arr[0];
    for(i=1;i<n;i++)
    {
        ans=a^arr[i];
        a=ans;
    }
    printf("%lld\n",ans);
    return 0;
}


/* HERE a is a variable having value at position zero and the then there is a variable which is equal to X-OR of element a and arr[i] and then we assign value of ans in variable a. 


if you find any bugs or more efficient solution than this than post in comments.

No comments:

Post a Comment