题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1510
1510. OrderTime limit: 1.0 second Memory limit: 16 MB A New Russian Kolyan likes two things: money and order. Kolyan has lots of money, but there is no order in it. One beautiful morning Kolyan understood that he couldn‘t stand this any longer and decided InputThe first line contains the number of Kolyan‘s banknotes N (1 ≤ N ≤ 500000). In the next N lines, the values K of these banknotes are given (0 ≤ K ≤ 109). OutputOutput the most common value. Sample
|
题意:
Output the most common value.
看最后一句就知道拉!
注意:G++超时,用C++交!
代码如下:
#include <cstdio> #include <cmath> #include <cstring> #include <string> #include <map> #include <iostream> #include <algorithm> using namespace std; map<int,int >a; int main() { int n; while(~scanf("%d",&n)) { int tt; int maxx = 0; int ans = -1; for(int i = 0; i < n; i++) { scanf("%d",&tt); a[tt]++; if(a[tt] > maxx) { ans = tt; maxx = a[tt]; } } printf("%d\n",ans); } return 0; }