codeup 5901

【题目描述】 
读入一串字符,判断是否是回文串。“回文串”是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串。

【输入】 
一行字符串,长度不超过255。

【输出】 
如果是回文串,输出“YES”,否则输出“NO”。

【样例输入】 
12321 
【样例输出】 
YES

AC代码:

#include<cstdio>  
#include<cstring>  
const int maxn=256;  
bool Judge(char str[])  //判断字符是否为回文串{  
    int lenth=strlen(str);  
    for(int i=0;i<lenth/2;i++)  
    {  
        //数组折中,i对应max-i-1   
        if(str[i]!=str[lenth-1-i])  
            return false;     
    }  
    return true;  
}  
int main()  
{     
    char cstr[maxn];  
    while(gets(str))  
    {  
        bool flag=Judge(str);  
        if(flag==true)  
        {  
            printf("%s","YES\n");  
        }  
            else  
        {  
            printf("%s","NO\n");      
        }      return 0;
    }  

猜你喜欢

转载自blog.csdn.net/qq_40696484/article/details/81003586