1. 程式人生 > >[C++]迴文字串判斷

[C++]迴文字串判斷

#include <iostream>
#include <string>
using namespace std;
inline bool is_palindrome(const string str) {
    int length = str.length();
    for (int i = 0; i < length / 2; ++i)
        if (str[i] != str[length - i - 1])
            return false;
    return true;
};
int main(int argc, char *argv[]) {
    ios::sync_with_stdio(false);
    string str; cin >> str;
    if (is_palindrome(str)) cout << "YES";
    else cout << "NO"; cout.put('\n');
    return 0;
};