[Codeup 5901] palindrome string

[Codeup 5901] palindrome string

Title Description
read a string of characters, whether or not palindromic sequence. "Palindrome string" is a positive reading and verlan same string, such as "level" or "noon" and so is a palindrome string.
An input
line of a character string of no more than 255.
Output
if the string is palindromic, output "YES", and otherwise outputs "NO".
Sample Input
12321
Sample Output
YES

#include <stdio.h>
#include <cstring>

bool judge(char str[]) {
    int length = strlen(str);
    //12321
    for (int i = 0; i < length / 2; i++) {
        //判断对称位置是否相同
        if (str[i] != str[length - i - 1]) {
            return false;
        }
    }
    return true;
}

int main() {
    char str[256];
    while (gets(str)) {
        if (judge(str)) {
            printf("YES\n");

        } else
            printf("NO\n");
    }


}

Test Results:
Here Insert Picture Description

Published 33 original articles · won praise 1 · views 4151

Guess you like

Origin blog.csdn.net/qq_39827677/article/details/103855268