Module: Associative arrays: map


Problem

2/9

Sorted Lists #1

Theory Click to read/hide

By default, data in lists is sorted by key in ascending order, it often happens that this sort order needs to be changed.
To do this, you can write a comparator that will position the data as you specify.

An example of a comparator that sorts in descending order of the key (written before main):

struct cmp
{
bool operator()(const string &< /span>a, const string &b) const
{
return a > b;
}
};

and is used when creating the list:

map<string, int, cmp> ; mymap;

Problem

Build Alpha-Frequency Dictionary: a list of words in alphabetical order, to the right of each word should indicate how many times it occurs in the source file. The sign of the end of the text is "END!". The list must be sorted by key in lexicographic descending order.
 
Input Output
one
two
one
three
two
one
END!
three 1
one 3
two 2