题目链接:

A. Voting for Photos

time limit per test

1 second
memory limit per test

256 megabytes

input

standard input

output

standard output

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 the i-th like.

Output

Print the identifier of the photo which won the elections.

Examples
input
5
1 3 2 2 1
output
2
input
9
100 200 300 200 100 300 300 100 200
output
300
Note

In the first test sample the photo with id 1 got two likes (first and fifth), photo with id 2 got two likes (third and fourth), and photo with id 3got one like (second).

Thus, the winner is the photo with identifier 2, as it got:

  • more likes than the photo with id 3;
  • as many likes as the photo with id 1, but the photo with the identifier 2 got its second like earlier.

AC代码:

#include <bits/stdc++.h>
using namespace std;
const int N=1e6+;
int flag[N],x[];
int main()
{
int n;
scanf("%d",&n);
memset(flag,,sizeof(flag));
for(int i=;i<n;i++)
{
scanf("%d",&x[i]);
flag[x[i]]++;
}
int ans=;
for(int i=;i<n;i++)
{
if(flag[x[i]]>ans)ans=flag[x[i]];
}
memset(flag,,sizeof(flag));
for(int i=;i<n;i++)
{
flag[x[i]]++;
if(flag[x[i]]==ans)
{
cout<<x[i]<<"\n";
break;
}
} return ;
}

codeforces 637A A. Voting for Photos(水题)的更多相关文章

  1. VK Cup 2016 - Qualification Round 1 (Russian-Speaking Only, for VK Cup teams) A. Voting for Photos 水题

    A. Voting for Photos 题目连接: http://www.codeforces.com/contest/637/problem/A Description After celebra ...

  2. codeforces Gym 100187H H. Mysterious Photos 水题

    H. Mysterious Photos Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/p ...

  3. codeforces 707A A. Brain's Photos(水题)

    题目链接: A. Brain's Photos 题意: 问是黑白还是彩色; 思路: 没有思路: AC代码: #include <iostream> #include <cstdio& ...

  4. 【Codeforces 707A】Brain's Photos 水题

    黑白灰都是#Black&White #include <cstdio> int n,m; int main() { scanf("%d%d",&n,&a ...

  5. Codeforces Round #368 (Div. 2) A. Brain's Photos 水题

    A. Brain's Photos 题目连接: http://www.codeforces.com/contest/707/problem/A Description Small, but very ...

  6. Educational Codeforces Round 7 B. The Time 水题

    B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...

  7. Educational Codeforces Round 7 A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...

  8. Codeforces Testing Round #12 A. Divisibility 水题

    A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...

  9. Codeforces Beta Round #37 A. Towers 水题

    A. Towers 题目连接: http://www.codeforces.com/contest/37/problem/A Description Little Vasya has received ...

随机推荐

  1. mysql海量数据条件删除

    1. 问题描述:现在存在两个表,具体表结构及记录数如下所示: mysql> desc user_mapping; +------------+------------------+------+ ...

  2. mysql慢查询日志分析工具(python写的)

    D:\NormalSoftware>python mysql_filter_slow_log.py ./mysql1-slow.log --no-duplicates --sort-avg-qu ...

  3. 九度OJ 1208:10进制 VS 2进制 (进制转换)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2040 解决:612 题目描述: 对于一个十进制数A,将A转换为二进制数,然后按位逆序排列,再转换为十进制数B,我们乘B为A的二进制逆序数. ...

  4. Zookeeper Curator 事件监听 - 秒懂

    目录 写在前面 1.1. Curator 事件监听 1.1.1. Watcher 标准的事件处理器 1.1.2. NodeCache 节点缓存的监听 1.1.3. PathChildrenCache ...

  5. Linux安装Nginx使用反向代理

    nginx的反向代理功能(自带了反向代理的功能,天生的二道贩子)1.实验环境准备准备2个服务器,都安装好nginx软件nginx1 192.168.13.79 作为web服务器 (理解为火车票售票点) ...

  6. 中国移动OnetNet云平台 使用WIFI模块ESP8266 TCP透传模式传输数据流步骤

    测试使用工具: WIFI模块型号:ESP8266 https://item.taobao.com/item.htm?spm=a1z10.1-c.w137712-175513579.2.btbD9X&a ...

  7. shell中替换json中指定的值

    在linux中部署软件的时候,有时会遇到用shell动态改动json格式的配置文件,比如一下rabbitmq.json文件: { "rabbitmq": { "ssl&q ...

  8. 模仿jquery框架源码

    <!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...

  9. HDU - 1175 连连看 【DFS】【BFS】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1175 思路 这种题一想到就用搜索, 但是内存是32m 用 bfs 会不会MLE 没错 第一次 BFS的 ...

  10. 【LeetCode】【找元素】Find First and Last Position of Element in Sorted Array

    描述: Given an array of integers nums sorted in ascending order, find the starting and ending position ...