A - Voting for Photos -- (利用映射乱搞)

来源:互联网 发布:se加密源码 编辑:程序博客网 时间:2024/05/29 17:13
A - Voting for Photos
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit Status

Description

After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rules to choose a winner: the photo which gets most likes wins. If multiple photoes get most likes, the winner is the photo that gets this number first.

Help guys determine the winner photo by the records of likes.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the total likes to the published photoes.

The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000), where ai is the identifier of the photo which got thei-th like.

Output

Print the identifier of the photo which won the elections.

Sample Input

Input
51 3 2 2 1
Output
2
Input
9100 200 300 200 100 300 300 100 200
Output
300

#include <stdio.h>#include <string.h>struct p{int d,id;}a[1000002];int main(){int n,i,x;scanf("%d",&n);for(i=1;i<=n;i++){scanf("%d",&x);a[x].d++;a[x].id=i;}int max=0;int flag=0;int flagid=1000000;for(i=1;i<=1000000;i++){if(a[i].d>max){max=a[i].d;flag=i;flagid=a[i].id;}else if(a[i].d==max&&flagid>a[i].id){max=a[i].d;flag=i;flagid=a[i].id;}}printf("%d\n",flag);return 0;}


0 0