有的詞倒過來讀還是它自己,比如 level、noon。寫 same_both_ways(word):模板已經影印了一份 back,用 reverse 把它倒過來,再和 word 比。大小寫不同算不一樣;空的也算一樣。
same_both_ways("level")→Truesame_both_ways("hello")→Falsebool same_both_ways(const string &word)#include <algorithm>
#include <string>
using namespace std;
bool same_both_ways(const string &word) {
string back = word;
// 在這裡寫:把 back 倒過來
return back == word;
}
寫好了先點「執行」試試示例,沒問題再點「提交」。