E
E
EvgenyApMr2021-06-06 18:46:48
C++ / C#
EvgenyApMr, 2021-06-06 18:46:48

How to split an incoming string into groups of characters with a count of their position?

Hello!

There is a school problem in C ++, but there were difficulties with the solution. For now, I'm just guessing that you need to apply search_n in a loop.

60bcedddaca7c959078697.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2021-06-06
@wataru

No, you just need to read n characters and maintain the current character, the start index of the group, and the length of the group.
When you read the symbol, if it is not equal to the previous one, then output the group. If equal, then increase the length of the group. After the loop, don't forget to output the last group. Also, for convenience, initially you need to initialize your variables with a group of length 1 from the first character and start iterating from the second.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question