Count the number of times each word occurs in a file

前端 未结 4 2014
挽巷
挽巷 2020-12-12 02:51

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

4条回答
  •  粉色の甜心
    2020-12-12 03:21

    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...

提交回复
热议问题