0
Why isn't this a valid solution?
No test validation
2 Respuestas
+ 1
Solution: change to i = word.size()-1
Explanation:
You have a blank character at every word you reversed, '\0'. It's used to terminate the string and it's the last character of every strings. At the first loop word[word.size()] is assigned to rword, which is '\0'. Starting from word.size()-1 will solve it.
0
#include <iostream>
#include <string>
using namespace std;
int main() {
int i = 0;
string word;
string rword = "";
cin >> word;
for (i = word.size(); i>=0; --i)
{
rword = word[i];
cout << rword;
}
return 0;
}