给你一个整数数列,保证只有一个数出现过奇数次,输出它。
多组测试数据。 每组测试数据第一行为一个整数n,代表该数列元素个数。(1 <= n <= 500000) 第二行为n个整数ai,以空格隔开。(-1000000 <= ai <= 1000000)
输出一行表示这个出现奇数次的数。
5
2 3 2 3 1
7
6 6 6 2 6 6 6
1
2
异或运算,ans异或任一数字两次,其值不变。
#include
#include
using namespace std;
typedef long long ll;
int main()
{
int n,x,ans;
while(~scanf("%d",&n))
{
ans=0;
for(int i=0;i<n;i++)
{
scanf("%d",&x);
ans^=x;
}
printf("%d\n",ans);
}
return 0;
}