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
#include<cstdio>
#include<algorithm>
using namespace std;
int a[1000005];
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
sort(a,a+n);
for(int i=0;i<n;i++)
{
if(a[i]==a[i+1])
{
printf("%d\n",a[i]);
break;
}
}
}
return 0;
}