#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <utility>
using namespace std;

int main() {
	const string data = "foofaaster";
	
	// populate the map
	map <char, int> chars;
	for (auto c = data.begin(); c != data.end(); ++c)
		chars [*c]++;
	
	// Now display the occurances
	cout << "Original data: '" << data << "'" << endl;
	multimap <int, char, greater <int>> counts;
	for (auto c = chars.begin(); c != chars.end(); ++c)
		counts.insert (make_pair (c->second, c->first));
	cout << "Character counts:" << endl;
	for (auto it = counts.begin(); it != counts.end(); ++it)
		cout << "\t" << it->first << ": '" << it->second << "'" << endl;

	
	return 0;
}