题目链接:

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
  1. 5
    1 3 2 2 1
output
  1. 2
input
  1. 9
    100 200 300 200 100 300 300 100 200
output
  1. 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代码:

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int N=1e6+;
  4. int flag[N],x[];
  5. int main()
  6. {
  7. int n;
  8. scanf("%d",&n);
  9. memset(flag,,sizeof(flag));
  10. for(int i=;i<n;i++)
  11. {
  12. scanf("%d",&x[i]);
  13. flag[x[i]]++;
  14. }
  15. int ans=;
  16. for(int i=;i<n;i++)
  17. {
  18. if(flag[x[i]]>ans)ans=flag[x[i]];
  19. }
  20. memset(flag,,sizeof(flag));
  21. for(int i=;i<n;i++)
  22. {
  23. flag[x[i]]++;
  24. if(flag[x[i]]==ans)
  25. {
  26. cout<<x[i]<<"\n";
  27. break;
  28. }
  29. }
  30.  
  31. return ;
  32. }

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. 用PreferenceActivity做一个标准的设置界面

    最后接触到一个任务,做一个工厂设置,在我看来工厂设置不需要多美观,但是一定要方便修改,添加功能,再就是使用方便,我就想到了用PreferenceActivity,android系统的settings就 ...

  2. cvm母机宕机重启后数据库修复

    下午正在开周会,然后收到短信,说是X.X.X.X的机器ping不通了,一轮测试过后,发现是某台数据库服务器挂了,先不急着重启,问下tencent客服... 乖乖的好家伙,母机的主板坏了....一个小时 ...

  3. iOS --创建文件夹 ,删除文件夹

    //创建文件夹 --> 返回 文件夹 - (NSString *)pathToPatientPhotoFolder { NSString *documentsDirectory = [NSSea ...

  4. [CMD]重启电脑

    https://zhidao.baidu.com/question/686086701903450132.html bat是批处理,可以调用关机命令关机. 制作方法如下: 打开记事本程序: 输入如下内 ...

  5. django form 表单验证

  6. WSGI协议解析

    WSGI协议中包含两个角色:服务器方和应用程序: 服务器方:其调用应用程序,给应用程序提供(环境信息)和(回调函数), 这个回调函数是用来将应用程序设置的http header和status等信息传递 ...

  7. zookeeper snowflake 实战

    目录 写在前面 1.1.1. 集群节点的命名服务 1.1.2. snowflake 的ID算法改造 SnowFlake算法的优点: SnowFlake算法的缺点: 写在最后 疯狂创客圈 亿级流量 高并 ...

  8. UVALive - 7045 Last Defence 【数学】

    题目链接 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  9. iOS 代码延迟执行

    1. [NSTread sleepForTimeInterval:0.8f] 这个方法 实际效果 好比打断点 等你再恢复断点执行 2.  [self performSelector:@selector ...

  10. Linux查看硬盘使用情况

    df df - report file system disk space usage df是查看文件系统磁盘使用情况的命令.如: # df -h Filesystem Size Used Avail ...