您的位置:首页 > 其它

【2012年腾讯俱乐部ACM赛新手组1004】XOR的用法-Poor man on the Single’s Day

2012-11-25 21:16 330 查看
这个是真没想到,CP的DISCUSS,给自己提个醒,原来位运算这么管用。有时会有奇效~

Description

  The Galapagos Islands are a nature lover's paradise. Isolated from the mainland for thousands of years, some of the most unusual species in the world evolved here, including giant tortoises, marine iguanas, blue-footed boobies, and even the world's only
equatorial penguin. The islands comprise the Galapagos National Park and were recently named a "World Heritage Site".

  On such a mysterious and beautiful island, there is a happy tribe. All the guys in this tribe are in pairs except one poor man. On the Single’s Day, can you help me find out this poor man?

  Every guy in the tribe has an id, if two guys are in pairs, they will have the same id. For example, there are five guys in the tribe, their ids are: 3, 9, 9, 3, 7. It means that the man with the id 7 is the poor man that we want to find out.

Input

Input consists of multiple test cases.   

The first line contains a number: n(there are n guys in the tribe); 0 < n <= 10 000 000 and n is an odd number;

And then there are n ids. The ids are out-of-order and in pairs except one id. 0 < id <= 10 000 000

Output

The id of the poor single man.

Sample Input
Copy sample input to clipboard

7
3 9 9 3 3 3 10


Sample Output

10


#include <iostream>  
#include <cstring>  
#include <cstdlib>  
#include <cstdio> 
#include <cmath>  
 
int n,t,ans=0; 
 
int main() 
{  
    while  (scanf("%d",&n)!=EOF)  
    {  
        for (int i=1;i<=n;i++) 
        {  
            scanf("%d",&t); 
            ans^=t; 
        }  
        printf("%d\ n",ans);  
        ans=0;  
    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: