Hi I am writing a program that counts the number of times each word occurs in a file. Then it prints a list of words with counts between 800 and 1000, sorted in the order of
A more efficient approach can be done with a single map< string, int >
of occurrences, read words one by one, and increment the counter in m[ word ]
. After all words have been accounted for, iterate over the map, for words in the given range, add them to a multimap
. Finally dump the contents of the multimap, that will be ordered by number of occurrences and alphabetical order...