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

A - Voting for Photos
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

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
5
1 3 2 2 1
Output
2
Input
9
100 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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值