Last active
May 18, 2017 09:04
Find the XOR of all sub-arrays of a given array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
using namespace std; | |
int main() | |
{ | |
int t; | |
cin >> t; | |
while(t--) | |
{ | |
int n; | |
cin >> n; | |
int i,j; | |
int num, result = 0; | |
for(i = 0; i < n; i++) | |
{ | |
cin >> num; | |
if(i % 2 == 0) | |
result = result ^ num; | |
} | |
if(n % 2 == 0) | |
cout << "0" << endl; | |
else | |
cout << result << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment