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