To approach this on the lines of a generic algorithm.
I would scan/read the line
word by word. Then maintain a data structure which stores the word and the number of times it occurs. The logic would be :-
1. Read the next word in the sentence.
2. Check if the word is already present in the data structure.
3. If present then increment the count associated.
4. If not present add the word to the data structure with a count of '1'.
5. Continue the process if there are more words.
At the end of the loop/iteration you have a data structure that contains all the words and the number of times it occurs.
Cheers,
Raj.