View Code of Problem 3929

#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

int main()
{
	int t;
	int n;
	long long a[10005];
	scanf("%d", &t);
	while(t--)
	{
		int count = 1, first = 1;
		long long sum;
		scanf("%d", &n);
		for(int i = 0; i < n; i++)
			scanf("%lld", &a[i]);
		sort(a, a+n);
		for(int i = 0; i < n-1; i++)
			if(a[i] == a[i+1])
				count++;
			else
			{
				if(count % 2 == 1)
					if(first)
					{
						sum = a[i];
						first = 0;
					}
					else
						sum = sum ^ a[i];
				count = 1;
			}
		if(a[n-2] != a[n-1])
			sum = sum ^ a[n-1];
		printf("%lld\n", sum);
	}
	return 0;
 } 

Double click to view unformatted code.


Back to problem 3929