+ 1

Code Coach Extra-terrestrials [SOLVED]

So, i'm using C++ for this code coach. When i tried it on pc, it work. And when i tried it on the "Result" on code coach, the outputs are exactly the same as the "Expected output", but i have no idea why did sololearn said that my test cases failed (5/5 test cases failed). I need help please. #include <iostream> #include <string.h> using namespace std; int main() { char x; char word[200]; cin.getline(word,200); x=strlen(word); for (int i=x; i>=0; i--) { if (word[i]==' ') { i=i-1; } cout << word[i]; } return 0; } https://www.sololearn.com/coach/51?ref=app

16th Jun 2020, 3:26 PM
Zack Evan
Zack Evan - avatar
3 RĂ©ponses
+ 4
#include <iostream> #include <string> using namespace std; string reversestr(string x){ string temp=""; int lens=x.length(); for (int i=lens - 1; i>=0 ; --i) { temp+=x[i]; } return temp; } int main() { string text; cin>>text; cout<<reversestr(text); return 0; } Here is your answer
16th Jun 2020, 4:29 PM
Harsh Sharma
Harsh Sharma - avatar
+ 4
#include <iostream> #include <string.h> using namespace std; int main() { int x; char word[200]; cin.getline(word,200); x=strlen(word); for (int i=x-1; i>=0; i--) { if (word[i]==' ') { i=i-1; } cout << word[i]; } return 0; }
16th Jun 2020, 4:32 PM
˜”*°‱.˜”*°‱ Mohan 333 ‱°*”˜.‱°*”˜
˜”*°‱.˜”*°‱ Mohan 333 ‱°*”˜.‱°*”˜ - avatar
0
Thank you guys, it works! ^^ Harsh Sharma , Mohan 333
16th Jun 2020, 11:35 PM
Zack Evan
Zack Evan - avatar