There are many ways that you could solve this, ranging from the incredibly simple, through to dramatic overkill. The thing that they all have in common is that they require you to break things down, step by step.
Let's analyse the problem here. You are starting with a fixed string (127a33069b1708r831c8457
), and you want to count the occurrence of each digit. From this, we know that we are limiting ourselves to numbers.
A simple pseudo-code solution to this could be:
Create a data structure to hold the character, and the count of times you have seen the character
Loop over the string until we have read all the characters
Get the character at the current index in the loop
If the character is a number
Look for the character and see if it is present in the data structure
If it is present, increment the count End If
If it is not present, add it and set the count to 1 End If
Create a counter to hold the total number of matched digits
Loop over the data structure
Print out the character and count
Add the count to the total in the counter above
Print out the counter