Calculator-T1125 Determine whether a string is a palindrome

Description

Enter a string, and output whether the string is a palindrome. A palindrome is a string that reads both forward and backward.

Input format

The input is a line of character string (there is no blank characters in the character string, and the character string length does not exceed 100100).

Output format

If the string is a palindrome, output "yes"; otherwise, output "no".

The extra spaces at the end of each line during output will not affect the correctness of the answer

Sample input

abcdedcba

Sample output

yes
#include <cstdio>
#include <iostream>
#include <cstring>

using namespace std;

char s[105];

int main()
{
    int len;
    int i;
    
    while (~scanf("%s", s)){
        len = strlen(s);
        for (i = 0; i <= len/2; i++)
            if (s[i] != s[len-1-i]){
                printf("no\n");
                break;
            }
        if (i == len/2+1)
            printf("yes\n");
    }
    
    return 0;
}

 

Guess you like

Origin blog.csdn.net/Aibiabcheng/article/details/105480423