c++ 判断数字和字符是否回文

点击查看代码
#include <iostream>
#include <cstring>

using namespace std;

const int MAX_N=256;

bool judge(char *a, int low, int high);

int main() {
    char s[MAX_N];
    cin>>s;
    bool flag= judge(s,0, ::strlen(s)-1);
    if (flag)   cout<<"YES";
    else    cout<<"NO";
    return 0;
}

bool judge(char *a, int low, int high) {
    for (int i = 0; i < high / 2; ++i) {
        if (a[i] != a[high - i]) {
            return false;
        }
    }
    return true;
}
posted @ 2023-02-23 10:32  冰糖人  阅读(70)  评论(0编辑  收藏  举报