+ 5

The Spy Life. Why test do not check

#include <iostream> using namespace std; int main() { const int A = 65, Z = 90, a = 97, z = 122, space = 32; string str, res; getline(cin, str); for (unsigned long int i = 0; i < str.length(); i++){ if (((str[i] >= A) && (str[i] <= Z)) || ((str[i] >= a) && (str[i] <= z)) || (str[i] == space)){ res += str[i]; } } int k = 0; for (unsigned long int i = res.length() + 1; i > 0;){ cout<<res[--i]; } return 0; }

10th Mar 2020, 12:55 PM
Imperator Teney
Imperator Teney - avatar
4 Antworten
+ 1
Use res.length(), instead of res.length()+1 & Try again.... And why need unsigned long int? int is enough..
10th Mar 2020, 4:04 PM
Jayakrishna 🇮🇳
+ 1
The program gives the expected answer, but the test fails.
10th Mar 2020, 2:29 PM
Imperator Teney
Imperator Teney - avatar
+ 1
Jayakrishna, thank you
11th Mar 2020, 12:13 PM
Imperator Teney
Imperator Teney - avatar
0
Imperator Teney you're welcome..
11th Mar 2020, 12:17 PM
Jayakrishna 🇮🇳