0

Why isn't this a valid solution?

No test validation

12th Sep 2020, 4:35 PM
Vlad Vizitiu
Vlad Vizitiu - avatar
2 odpowiedzi
+ 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.
12th Sep 2020, 5:11 PM
你知道規則,我也是
你知道規則,我也是 - avatar
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; }
12th Sep 2020, 4:35 PM
Vlad Vizitiu
Vlad Vizitiu - avatar