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

book
Practice with the Continue Keyword in C++ Loops

Tâche

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.

  1. Fill new string with a valid characters (omit exclamation marks) from the corrupted string.
  2. Output new fixed string.

Solution

cpp

solution

#include <iostream>
#include <string>

int main()
{
std::string corrupted_id = "!!I!D: 7f!3!!b!92!d!!4-!!!!a!b!c!!1!!-5!!!6a7-9!!d!2f!!";
std::string fixed_id = "";

int index = 0;
while (index < corrupted_id.length())
{
if (corrupted_id[index] == '!')
{
index++;
continue;
}
fixed_id += corrupted_id[index];
index++;
}
std::cout << fixed_id << std::endl;
}

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 5
#include <iostream>
#include <string>

int main()
{
std::string corrupted_id = "!!I!D: 7f!3!!b!92!d!!4-!!!!a!b!c!!1!!-5!!!6a7-9!!d!2f!!";
std::string fixed_id = "";

int ___ = 0;
while (___)
{
if (___ == ___)
{
___++;
___;
}
fixed_id += corrupted_id[index];
___++;
}
std::cout << fixed_id << std::endl;
}

Demandez à l'IA

expand
ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

some-alt