+ 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
3 Antworten
+ 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
+ 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;
}
0
Thank you guys, it works! ^^ Harsh Sharma , Mohan 333