0
Extra terrestrial answer test failing but my output is exactly the same
#include <iostream> using namespace std; int main() { string word; cin >>word; string reverse; for(int i=word.length();i>=0;i--){ reverse+=word[i]; } cout << reverse; return 0; }
3 ответов
+ 1
Start with
int i = word.length() -1
+ 1
Jayakrishna🇮🇳 Thanks, it worked.. But why?
+ 1
Indexes starts from 0 , not 1
Ex: if word = "abcde";
It return word.length() as 5, but maximum valid index is 4 only. and 5 is out of range
Valid indexes are 0 to length-1 only..