有的词倒过来读还是它自己,比如 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;
}
写好了先点「运行」试试示例,没问题再点「提交」。