自己代码:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include <algorithm>
#pragma warning(disable:4996)
using namespace std;
int a[10000000];
int main()
{
int n,i;
while (~scanf("%d", &n))
{
int count=1,qi;
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
sort(a, a + n);
for (i = 0; i < n; i++)
{
qi = a[i];
if (qi == a[i + 1])
count++;
else if (count % 2 == 0)
count = 1;
else
{
qi = a[i];
break;
}
}
printf("%d\n", qi);
}
return 0;
}
用异或的代码:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include <algorithm>
#pragma warning(disable:4996)
using namespace std;
int a[10000000];
int main()
{
int n,i;
while (~scanf("%d", &n))
{
int count=1,qi=0;
for (i = 0; i < n; i++)
{
scanf("%d", &a[i]);
qi=qi^a[i];
}
printf("%d\n", qi);
}
return 0;
}