Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Challenge: Practice with the Continue Keyword in C++ Loops | While Loop
C++ Loops

bookChallenge: Practice with the Continue Keyword in C++ Loops

Taak

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.

  1. Initialize the variable fixed_id as an empty string.
  2. Initialize the variable index as 0. This will act as an iterator to track the current position in the corrupted_id string.
  3. Use a while loop to iterate through the string until index reaches the size of the string. You can get the size of the string using the length() method.
  4. Inside the loop, check if the current character is '!'. If it is, increment index and continue to skip adding it.
  5. If the character is not '!', append it to fixed_id.
  6. Increment index by one on each iteration.
  7. After the loop finishes, return fixed_id as the cleaned ID.

Oplossing

solution.cpp

solution.cpp

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 5
single

single

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

close

Awesome!

Completion rate improved to 9.09

bookChallenge: Practice with the Continue Keyword in C++ Loops

Veeg om het menu te tonen

Taak

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.

  1. Initialize the variable fixed_id as an empty string.
  2. Initialize the variable index as 0. This will act as an iterator to track the current position in the corrupted_id string.
  3. Use a while loop to iterate through the string until index reaches the size of the string. You can get the size of the string using the length() method.
  4. Inside the loop, check if the current character is '!'. If it is, increment index and continue to skip adding it.
  5. If the character is not '!', append it to fixed_id.
  6. Increment index by one on each iteration.
  7. After the loop finishes, return fixed_id as the cleaned ID.

Oplossing

solution.cpp

solution.cpp

Switch to desktopSchakel over naar desktop voor praktijkervaringGa verder vanaf waar je bent met een van de onderstaande opties
Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 5
single

single

some-alt