Challenge: Practice with the Continue Keyword in C++ Loops
Swipe to start coding
The ID
string has been corrupted and is currently saturated with exclamation marks (!
). You were chosen to restore the original data it was holding.
All the code should be implemented inside the fixId
function.
- Initialize the variable
fixed_id
as an empty string. - Initialize the variable
index
as0
. This will act as an iterator to track the current position in thecorrupted_id
string. - Use a
while
loop to iterate through the string untilindex
reaches the size of the string. You can get the size of the string using thelength()
method. - Inside the loop, check if the current character is
'!'
. If it is, incrementindex
andcontinue
to skip adding it. - If the character is not
'!'
, append it tofixed_id
. - Increment
index
by one on each iteration. - After the loop finishes, return
fixed_id
as the cleaned ID.
Lösung
solution.cpp
Danke für Ihr Feedback!
single
Fragen Sie AI
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen
Can you explain this in simpler terms?
What are some examples related to this topic?
Where can I learn more about this?
Awesome!
Completion rate improved to 9.09
Challenge: Practice with the Continue Keyword in C++ Loops
Swipe um das Menü anzuzeigen
Swipe to start coding
The ID
string has been corrupted and is currently saturated with exclamation marks (!
). You were chosen to restore the original data it was holding.
All the code should be implemented inside the fixId
function.
- Initialize the variable
fixed_id
as an empty string. - Initialize the variable
index
as0
. This will act as an iterator to track the current position in thecorrupted_id
string. - Use a
while
loop to iterate through the string untilindex
reaches the size of the string. You can get the size of the string using thelength()
method. - Inside the loop, check if the current character is
'!'
. If it is, incrementindex
andcontinue
to skip adding it. - If the character is not
'!'
, append it tofixed_id
. - Increment
index
by one on each iteration. - After the loop finishes, return
fixed_id
as the cleaned ID.
Lösung
solution.cpp
Danke für Ihr Feedback!
single