Kodewick
Start learning →
Basic←→0 / 60

Same both ways

#051BasicAlgorithmsStrings4 min

Some words read the same backwards, like level and noon. Write same_both_ways(word): the starter already copies it into back; use reverse to turn back around, then compare it with word. Different capitals count as different; an empty word counts as the same.

Examples
same_both_ways("level")→True
same_both_ways("hello")→False
The functionbool same_both_ways(const string &word)
main.cpp
#include <algorithm>
#include <string>
using namespace std;

bool same_both_ways(const string &word) {
    string back = word;
    // your code here: reverse back
    return back == word;
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.