1. 程式人生 > >【暑期基礎2】D HDU Palindromes _easy version(水:迴文字串)

【暑期基礎2】D HDU Palindromes _easy version(水:迴文字串)

迴文字串的水題

#include <stdio.h>
#include <ctype.h>
#include <string.h>

int main() {
    int n, i, j, length;
    int status;
    char palindrome[100];
    scanf("%d\n", &n);

    while ( n--) {
        status = 1;
        fgets(palindrome, 100, stdin);
        j = strlen( palindrome ) - 2;
        for ( i = 0; i < j; i++, j--) {
            if ( palindrome[i] != palindrome[j]) {
                status = 0;
                break;
            }
        }
        if ( status ){
            printf("yes\n");
        } else {
            printf("no\n");
        }
    }
    return 0;
}