您的位置:首页 > 大数据 > 人工智能

Duplicate Pair(异或操作)

2015-07-18 12:49 579 查看
Link:http://acm.fzu.edu.cn/problem.php?pid=1001

Problem 1001 Duplicate Pair

Accept: 4923 Submit: 23300

Time Limit: 1000 mSec Memory Limit : 65536 KB



Problem Description

An array of length n, with address from 1 to n inclusive, contains entries from the set {1,2,...,n-1} and there's exactly two elements with the same value. Your task is to find out the value.



Input

Input contains several cases.

Each case includes a number n (1<n<=10^6), which is followed by n integers.

The input is ended up with the end of file.



Output

Your must output the value for each case, one per line.



Sample Input

21 141 2 3 2



Sample Output

12



Source

IBM Challenge 2004.1

AC code:

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