我需要编写一个函数,它接受像“abcdef”这样的字符串并将其转换为“af”,或将“589”转换为“5-9”,我可以使用 stdio.h 和 string.h 中的哪些函数?
You need to find the start and end of runs. It's easier if you consider every character to be part of a run, so you might runs of length 1 or more.
When you find the end of a run, you need to do different things depending on the length of the run.
With that in mind, we could use the following algorithm:
You should run through the above algorithm on paper, with "4abcz35xy"
as input. While you do, keep track of the current value of the variables (the pointer, the run length and the saved character).
+---+---+---+---+---+---+---+---+---+---+---+
|'4'|'a'|'b'|'c'|'z'|'3'|'4'|'5'|'x'|'y'| 0 |
+---+---+---+---+---+---+---+---+---+---+---+
^
Pointer |
+-------+ |
| -----+
+-------+
Run length
+-------+
| |
+-------+
Saved character
+-------+
| |
+-------+
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.