奇数个的那个数

Description

给定些数字,这些数中只有一个数出现了奇数次,找出这个数。

Input

每组数据第一行n表示数字个数,1 <= n <= 2 ^ 18 且 n % 2 == 1。

接下来n行每行一个32位有符号整数。

Output

出现奇数次那个数,每组数据对应一行。

Sample Input

5
1
1
2
2
3

7
1
2
1
2
2
3
3

Sample Output

3
2

Hint


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=1e6+10;
int a[maxn];
int main()
{
	int n,num,cnt;
	while(scanf("%d",&n)!=EOF)
	{
	
		for(int i=0;i<n;i++)
			scanf("%d",&a[i]);
		sort(a,a+n);
		cnt=1;
		int k;
		for(k=0;k<n-1;k++)
		{
			if(a[k]==a[k+1]) cnt++;
			else 
			{
				if(cnt & 1) break;
				else cnt=1;
			}
				
		}
		
		printf("%d\n",a[k]);
	}
	
	return 0;
}
/**********************************************************************
	Problem: 1217
	User: song_hai_lei
	Language: C++
	Result: AC
	Time:460 ms
	Memory:5928 kb
**********************************************************************/


猜你喜欢

转载自blog.csdn.net/song_hai_lei/article/details/80427902