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.
- Fill new string with a valid characters (omit exclamation marks) from the corrupted string.
- Output new fixed string.
Solution
solution
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#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 ?
Merci pour vos commentaires !
Section 1. Chapitre 5
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#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
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion