设为首页 加入收藏

TOP

HUNNU Contest 找数字2
2015-07-24 06:37:26 来源: 作者: 【 】 浏览:30
Tags:HUNNU Contest 数字
找数字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<
           
           


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C++ - string类型转换int类型 下一篇VC++环境下多文档模板应用程序开..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: