I am true at 4 test Case but i fail at test case 5, what was wrong with my code. Extra terrestrial. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I am true at 4 test Case but i fail at test case 5, what was wrong with my code. Extra terrestrial.

#include <iostream> using namespace std; int main() { String s; Cin>>s; Int d=s.length()-1; Char a[d]; For(int i=0;i<=d; i++) a[i]=s[d-i]; Cout<<a; Return 0;}

9th Feb 2020, 7:22 AM
Hiếu Võ Trần Minh
Hiếu Võ Trần Minh - avatar
7 Answers
+ 2
which one is it? ahhh extra terristical... please put inti question not only tag
9th Feb 2020, 7:24 AM
Oma Falk
Oma Falk - avatar
+ 2
Dont use the for loop use the built in library of c++ which reverses the string Like #include <bits/stdc++.h> using namespace std int main(){ String s; Cin>>s; reverse(s.begin(),s.end()); cout<<s<<endl; }
19th Apr 2020, 11:59 AM
100 subs with 2 videos
100 subs with 2 videos - avatar
+ 1
you can reverse and print it on the fly, without using another variable. string s; cin >> s; int d=s.length()-1; for(int i=d;i >=0; i--){ cout << s[i]; }
9th Feb 2020, 8:14 AM
Bahhaⵣ
Bahhaⵣ - avatar
+ 1
or for your original code, add +1 in for loop. for(int i=0;i<=d+1; i++) a[i]=s[d-i];
9th Feb 2020, 8:21 AM
Bahhaⵣ
Bahhaⵣ - avatar
+ 1
I've done, thank you very much.
9th Feb 2020, 8:29 AM
Hiếu Võ Trần Minh
Hiếu Võ Trần Minh - avatar
0
Thank you!
9th Feb 2020, 7:47 AM
Hiếu Võ Trần Minh
Hiếu Võ Trần Minh - avatar
0
But, why it need +1, I think a[d] is the end.
9th Feb 2020, 8:31 AM
Hiếu Võ Trần Minh
Hiếu Võ Trần Minh - avatar