i need to make a program which reads multiple lines from stdin count the words and then print the words with the number of ocurrence but if two or more words have the same number i have to sort them alphabetically. E.g:
hello world
good morning
hello
The output should be:
hello: 2
good: 1
morning: 1
world: 1
I want to know which is the best way to do this, is hashmap the best way?