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;}
7 Antworten
+ 2
which one is it?
ahhh extra terristical...
please put inti question not only tag
+ 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;
}
+ 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];
}
+ 1
or for your original code, add +1 in for loop.
for(int i=0;i<=d+1; i++) a[i]=s[d-i];
+ 1
I've done, thank you very much.
0
Thank you!
0
But, why it need +1, I think a[d] is the end.