Skip to main content
Logo image

Section 22.7 Sorting Practice

In the problem below you may use any sorting technique you wish to use!

Activity 22.3.

You are still conducting linguistic research! This time, you’d like to find out how many letters occur multiple times in a given word. To do so, you will read a word from the input and then sort the letters of the word alphabetically (by their ASCII codes). Next, you go through the letters of the word and compare a letter with the one following it. If these equal each other, you increase a counter by 1, making sure to next skip ahead far enough so that letters that occur more than twice are not counted again. You may assume that the word you read from the input has no more than 50 letters.
Here are some examples:
Input: apple
Output: 1
Input: keeper
Output: 1
Input: erroneousnesses
Output: 5
Input: Taylor
Output: 0

admin.....open in new window