2088 实验11字符串:回文

Time Limit : 2000/1000 MS(Java/Others) | Memory Limit : 131072/65536 KB(Java/Others)

Submits : 12 | Solved : 10

Description

编写函数,判断一个字符串是否是回文。若是回文函数返回值为1,否则返回值为0。回文是顺读和倒读都一样的字符串。

Input

所有输入在合法范围内,且输入字符串长度<=19。输入有5组测试数据。

Output

在主函数中输入要判断的字符串,调用函数,输出 “yes” (是回文)或“no”。(不是)

Sample Input

1ere1
sdfgg
1221
shh
0000

Sample Output

yes
no
yes
no
yes

HINT

#include < stdio.h >
#include < string.h >
int main(){
  char s[20]="";
  int len,count;
  char *start,*end;
  for (count=1;count<=5;count++){
    scanf("%s",s);
    start=s;            /*字符串头指针*/
    len=strlen(s);
    end=s+len-1;          /*字符串尾指针*/
    for (;start<=end;start++,end--){
      if (*start!=*end) break;
    }
    if (start<=end) printf("%s\n","no");
    else printf("%s\n","yes");
  }
}

Source


[ Top ] | [ Submit ]