+ 1

YouTube links challenge not accepting correct answer?

I tried to solve the YouTube links challenge with cpp. My code seemed to have given the correct output but it wasn't accepted as correct. This is the code: '''cpp #include <iostream> #include <algorithm> using namespace std; int main() { string url; string result; cin >> url; for (size_t i=url.size();i>0;i--) { if (url[i]=='='||url[i]=='/') { break; } result += url[i]; } reverse(result.begin(), result.end()); cout <<result; return 0; } '''

15th Jan 2024, 8:53 PM
Alejandra Camus
Alejandra Camus - avatar
4 Answers
+ 3
Do any of the test cases pass? Does it fail on any of the test cases?
16th Jan 2024, 2:12 AM
Keith
Keith - avatar
+ 2
Alejandra Camus the problem is that your output includes the non-printable terminating null from the end of the input string. HINT: Check your loop limits.
16th Jan 2024, 4:28 PM
Brian
Brian - avatar
+ 2
Brian , good catch. Solved!
16th Jan 2024, 4:48 PM
Alejandra Camus
Alejandra Camus - avatar
+ 1
The first 2 test cases (the only ones unlocked) fail, even though the output of the test cases seems to be exactly the output of my program in both test cases
16th Jan 2024, 4:39 AM
Alejandra Camus
Alejandra Camus - avatar