问题
题目:[回文字符串]
思路
两种思路:
- 判断对称元素是否相等
- 判断源字符串与逆序字符串是否相等
代码
#include <iostream>
#include <string>
#include <algorithm>
bool is_palindrome(const std::string& s);
int main( void )
{
std::string s;
while( std::cin >> s )
{
bool ret = is_palindrome( s );
if( ret )
std::cout << "Yes!" << std::endl;
else
std::cout << "No!" << std::endl;
}
return 0;
}
bool is_palindrome(const std::string& s)
{
return std::equal( s.begin(), s.end(), s.rbegin());
}