I’m trying to write pseudocode for an algorithm that takes a string of digits as input and outputs a new string that “describes” the original string using counts of consecutive digits.
For example:
- Input: “22111344”
- Output: “22311324”
Explanation:
The output describes the counts of consecutive digits in the input string:
- “22” means there are two 2s.
- “111” means there are three 1s.
- “3” means there is one 3.
- “44” means there are two 4s.
I’m having trouble breaking this down into simple pseudocode and structuring the algorithm clearly. Could someone provide guidance or suggestions on how to approach this problem?
Declare String digits
Display "Enter a string of digits"
Input digits
Declare currentNum = read in first number
Declare secondNum = read in next number
Declare count = 0
while Numbers are Present
if currentNum == secondNum
count = count + 1
else if
Display count + currentNum
ciara laird is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2