String processing I: counting, runs and building
- Stage
- 3
- Module
- M3.3
- Lessons
- 1
In this module
- Iterate through a string character by character to count runs of identical characters.
- Build a new string by appending characters inside a loop.
- Detect when a character changes and reset a counter.
Before this module
Lessons
Practice
Try these on the judges. Each link opens the problem on WMOJ or DMOJ.
- 2022 J3Harp Tuning (opens on WMOJ in a new tab) WMOJ
Compress a string by counting consecutive identical characters.
- 2020 S1Surmising a Sprinter's Speed (opens on DMOJ in a new tab) DMOJ
Scan a list of values and sort them to work out a consistent pattern.
Why DMOJ: A scan-and-sort problem that reuses the character-by-character pass from this lesson.
- 2024 J3Bronze Count (opens on WMOJ in a new tab) WMOJ
Find a specific ranked value among a set of scores, by counting or sorting.