words_palin_2.cpp
来自「A group of word-analysis examples for C+」· C++ 代码 · 共 37 行
CPP
37 行
/*
* Description:
*
* Examine whether a string is a palindrome.
*
* History:
*
* Initial version created by Royal, Mar. 2004.
*
* Notes:
*
* This code has been written to conform to standard C++ and STL. It has been
* compiled successfully using GNU C++ 3.2, Borland C++ 5.5, and Visual C++ 7.0.
*/
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
bool is_palindrome(const string& s)
{
return equal(s.begin(), s.end(), s.rbegin());
}
int main()
{
string s;
while (cin >> s)
{
if (is_palindrome(s)) cout << "\"" << s << "\"" << " is a palindrome" << endl;
else cout << "\""<< s << "\"" << " is not a palindrome" << endl;
}
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?