FZU 1001 Duplicate Pair(简单题目)

来源:互联网 发布:002航母知乎 编辑:程序博客网 时间:2024/04/27 19:45

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;}
0 0
原创粉丝点击