Boo*_*jum 3 c++ iterator function
rbegin() 和 rend() 在以下函数中究竟做了什么来确定输入是否为回文?
bool palindromeCheck(string input) {
if (input == string(input.rbegin(), input.rend())) {
return true;
}
else {
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
其中一个forstd::string
的构造函数将一对迭代器作为输入。rbegin()
返回指向原始input
字符串最后一个字符的rend()
反向迭代器,并返回指向原始input
字符串第一个字符之前的字符(即字符串“结尾”之后的字符)的反向迭代器。
结果是构造了一个与原始字符串相反的新字符串,如果该新字符串等于原始字符串,则它是一个回文,函数返回 true。
归档时间: |
|
查看次数: |
3472 次 |
最近记录: |