Maximum number of occurrences

Source: Internet
Author: User

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.