March 15 CCF Real Title 2-Sort by number

Source: Internet
Author: User

Problem description

given n integers, count the number of occurrences of each integer and output in the order of occurrences, from many to fewer.

Input format

The first line of input contains an integer n, which represents the number of a given number.
The second row contains n integers, separated by a space between adjacent integers, representing the given integer.

Output format

Outputs multiple lines, each containing two integers, representing a given integer and the number of times it appears. Output in descending order of occurrences. If two integers occur as many times as possible, the output value is smaller and the output value is larger.

Sample input

12
5 2 3 3 1 3 4 2 5 2 3 5

Sample output

3 4
2 3
5 3
1 1
4 1

Measuring use case size and conventions

1≤n≤1000, the given number is a non-negative integer of not more than 1000.

Take advantage of the automatic sequencing of maps and Multimap to get you straight.

1#include <iostream>2#include <map>3 4 using namespacestd;5 6 intMain () {7map<int,int>J;8multimap<int,int,greater<int>>JJ;9     intN;TenCin>>N; One      for(intI=0; i<n;i++) A     { -         intA; -Cin>>A; thej[a]++; -     } -      for(map<int,int>::iterator it = J.begin (); It!=j.end (); it++) -     { +Jj.insert (pair<int,int> (it->second,it->First )); -     } +      for(map<int,int>::iterator it = Jj.begin (); It!=jj.end (); it++) A     { atcout<<it->second<<" "<<it->first<<Endl; -     } -         return 0; -}

March 15 CCF Real Title 2-Sort by number

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.