[codeup 5901]回文串

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#define maxn 300
using namespace std;
char str[maxn];
bool isBackStr() {
    bool flag = true;
    int half, len = strlen(str);
    if(len % 2) half = (len - 1) / 2;
    else half = len / 2;
    for(int i = 0; i < half; i++) {
        if(str[i] != str[len-1-i]) {
            flag = false;
            break;
        }
    }
    return flag;
}

int main() {
//    FILE* in = fopen("/home/zzz/input.txt", "r");
//    while (fscanf(in, "%s", str) != EOF) {
//        if(isBackStr()) cout << "YES" << endl;
//        else cout << "NO" << endl;
//    }

    while (scanf( "%s", str) != EOF) {
        if(isBackStr()) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}
posted @ 2019-10-11 15:31  明卿册  阅读(104)  评论(0编辑  收藏  举报