Maximum number of occurrences
The Problem description is given with n positive integers to find the maximum number of occurrences among them. If there are multiple such numbers, output the smallest one. Input Format
The first line of the input has only one positive integer n (1 ≤ n ≤ 1000), indicating the number of numbers.
The second line of the input has n integers s1, s2 ,..., Sn (1 ≤ si ≤ 10000, 1 ≤ I ≤ n ). Adjacent numbers are separated by spaces.
The output format outputs the maximum number of times of n. If there are multiple such numbers, the smallest one is output. Sample Input
6
10 1 10 20 30 20
Sample output
10
Code:
/*************************************** *************************************//* CCF software proficiency test simulation questions-the most frequently asked questions: Ripper *//*********************** **************************************** * ************/# include
# Include
Using namespace std; int main () {// assert (freopen (CCF \ mostOftenNum. in, r, stdin); int n, num; typedef map
IntIntMap; intIntMap numCount; cin> n; for (int I = 0; I <n; I ++) {cin> num; numCount [num] ++ ;} int max_num = INT_MIN, max =-1; for (intIntMap: iterator pos = numCount. begin (); pos! = NumCount. end (); pos ++) {// cout <
First <: <pos-> second <endl; if (pos-> second> max | (pos-> second = max & pos-> first <max_num) {max = pos-> second; max_num = pos-> first ;}} cout <max_num <endl; // fclose (stdin); return 0 ;}
From: http://blog.csdn.net/pipisorry/article/details/39434403