Another test

Problem 1001 Duplicate Pair

Accept: 5142    Submit: 24343
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

2 1 1 4 1 2 3 2

Sample Output

1 2

Source

IBM Challenge 2004.1 
 1 #include <cstdio>
 2 #include <cstring>
 3 int a[1000005];
 4 int main()
 5 {
 6     int n;
 7     while(scanf("%d",&n) != EOF)
 8     {
 9 
10         memset(a,0,sizeof a);
11         int ans = 0;
12         for(int i = 0 ; i < n ; i++)
13         {
14             int temp;
15             scanf("%d",&temp);
16             a[temp]++;
17             if(a[temp] == 2) ans = temp;
18         }
19         printf("%d\n",ans);
20     }
21     return 0;
22 }
View Code

 

posted @ 2016-04-18 00:47  昵称还没有想归一  阅读(171)  评论(0编辑  收藏  举报