Kodewick
開始學 →
基礎←→0 / 86

正著倒著一樣

#051基礎reverse(…)約 4 分鐘

有的詞倒過來讀還是它自己,比如 level、noon。寫 same_both_ways(word):模板已經影印了一份 back,用 reverse 把它倒過來,再和 word 比。大小寫不同算不一樣;空的也算一樣。

示例
same_both_ways("level")→True
same_both_ways("hello")→False
函式bool 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;
    // 在這裡寫:把 back 倒過來
    return back == word;
}
Ctrl + Enter 也能執行
結果

寫好了先點「執行」試試示例,沒問題再點「提交」。