Search This Blog

Thursday 25 August 2016

SPOJ - Onotole needs your help Using XOR

SPOJ - Onotole needs your help Using XOR

Solution:-

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int N,num,one_num=0;
    scanf("%d",&N);
    for(int i=0;i<N;i++)
    {
        scanf("%d",&num);
        one_num^=num;
    }
    printf("%d",one_num);
    return 0;

}

//Just a Lillte Piece of Advice, use scanf and printf instead of cin and cout as they will work fast in this scenario. (To get AC :P)

Or
if you are c++ crazy, you can turn off the sync with stdio, to make cin & cout runs faster (equal or even faster than scanf,printf)
to do that,use

std::ios::sync_with_stdio(false);

No comments:

Post a Comment