Problem 1001 Duplicate Pair

来源:互联网 发布:linux syslog配置 编辑:程序博客网 时间:2024/04/27 19:38
/*
 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
2
1 1
4
1 2 3 2
Sample Output
1
2


*/

int sum[1000000]={0};int main(){long i,j,data;while(scanf("%ld",&i)!=EOF){for(j=0;j<i;j++){scanf("%ld",&data);sum[data]++;}for(j=0;j<1000000;j++){if(sum[j]==2){printf("%ld\n",j);}sum[j]=0;}}return 0;}