+ 1

(SOLVED)Extra-Terrestrials my code answer is incorrect. Pls, why?

Pls someone can tell me why my answer is not accepted? All tests fail my code.. https://code.sololearn.com/cc68eRVy1L0g thanks

23rd Jun 2020, 11:00 PM
Bruno Franco
Bruno Franco - avatar
3 ответов
+ 3
Because there is a '\0' before every reversed strings. The first loop in for loop cause it. When k = 0 you assign word + str[length] to word, whereas str[length] is '\0'. To solve it, make k = 1. for(int k = 1 ; k <= length ; k++)
24th Jun 2020, 12:33 AM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 4
CarrieForle is correct. It's due to the string null terminating character '\n'. Loop through the string starting from the last visible character to 0. for(int k = length-1; k >= 0 ; k--) { word = word + str[k]; }
24th Jun 2020, 12:39 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
thank you guys. CarrieForle you are right. thank so much ,i haven't seen it before😩
24th Jun 2020, 1:10 AM
Bruno Franco
Bruno Franco - avatar