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.
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
#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;
}