Given two sets of a and B, find the smallest nonnegative integer x to make the a⊕x=b.
Suppose A={a1,a2,..., an}, A⊕x={a1⊕x,a2⊕x,..., an⊕x}.⊕ represent XOR or operation
The first line of input inputs is an integer t representing a total of T-group test data;
For each set of test data, the first row is an integer n representing the size of the collection A and B
The second line contains n integers a1,a2,a3,.... An, which represents the elements of collection A.
The third line contains n integers b1,b2,b3,.... bn, representing the elements of collection B.
(1<=n<=100000,n is odd, 0<=ai<2^30)
Output if x is present, outputs the smallest x, or 1 if it does not exist. Sample Input 1
3
0 1 3
1 2 3
Sample Output 2
#include <stdio.h>
#include <algorithm>
using namespace std;
int main ()
{
int t,n,ans,f,i;
int a[100005],b[100005],c[100005];
scanf ("%d", &t);
while (t--)
{
scanf ("%d", &n);
ans=0;
for (i=0;i<n;i++)
{
scanf ("%d", &a[i]);
Ans=ans^a[i];
}
for (i=0;i<n;i++)
{
scanf ("%d", &b[i]);
Ans=ans^b[i];
}
for (i=0;i<n;i++)
c[i]=ans^a[i];
Sort (c,c+n);
Sort (b,b+n);
f=0;
for (i=0;i<n;i++)
{
if (C[i]==b[i])
continue;
else
{
f=1;
break;
}
}
if (f==1)
printf (" -1\n");
else
printf ("%d\n", ans);
}
return 0;
}