2013判断回文字符串

在这里插入图片描述

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

int judge(char *s)
{//判断字符串是否是回文串
    int len = strlen(s);
    int i=0,j=len-1;
    for(i=0,j=len-1;s[i]==s[j]&&i<j;i++,j--);
    if(j<=i)    return 1;
    else return 0; 
}

int main()
{
    char *s=(char*)malloc(sizeof(char)*100);
    int cnt=0;
    while(scanf("%s", s)!=EOF)
    {
        cnt++;
        if(judge(s))
            printf("case%d: yes\n", cnt);
        else
            printf("case%d: no\n", cnt);
    }
    return 0;
}
发布了98 篇原创文章 · 获赞 9 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_43661234/article/details/103864079