Read the question, write C++ on the right, then Run or Check.
QuestionHint and solution stay closed until you open them
Read one word and print it reversed.
std::reverse edits the string in place — no second string needed.
Input. One line: a word.
Output. The word, reversed.
Examples
Input
code
Output
edoc
Input
C++
Output
++C
Hint
- #include <algorithm> for std::reverse.
- std::reverse(word.begin(), word.end());
Show correct code
Peek only after you have tried. You can still Check your own version.
#include <iostream>
#include <string>
#include <algorithm>
int main() {
std::string word;
std::cin >> word;
std::reverse(word.begin(), word.end());
std::cout << word << "\n";
return 0;
}
main.cppC++17 · g++ · Ctrl + Enter runs
ResultIdle
Run to see output. Check grades the tests.