HUNNU Contest 找数字2

2015-07-24 06:37:26 · 作者: · 浏览: 31
找数字2
Time Limit: 25000ms, Special Time Limit:50000ms, Memory Limit:32768KB
Total submit users: 108, Accepted users: 87
Problem 11466 : No special judgement
Problem description
给定2n+1个数字,只有一个数字出现了奇数次,其余的数字都出现了偶数次,现在你需要找出出现奇数次的数字。
Input
包含多组数据,每组数据第一行为一个数n(0<=n<=5000000)。接下来一行包括2n+1个数字(小于1000000000)。
Output
对于每组数据,输出出现奇数次的数字.
Sample Input
1
1 1 1
2
1 2 1 3 3
3
1 1 2 2 3 3 4
Sample Output
1
2
4
Problem Source

HUNNU Contest

//这道题 还是蛮简单的,用到异或操作,因为题目只有一个数出现奇数次,但是相同的数异或一定为0,所以一直异或最后剩下的自然是出现奇数次的数。

#include
      
       
int main()
{
    int n,i,a,ans;
    while(scanf("%d",&n)!=EOF)
    {
        ans=0;
        for(i=0;i<2*n+1;i++)
        {
            scanf("%d",&a);
            ans^=a;
        }
        printf("%d\n",ans);
        /*for(it=m.begin();it!=m.end();it++)
        {
            //cout<
       
        second<
        
         second)%2!=0) break; } cout<
         
          first<