题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2029
这题不用for循环判断,直接用strrev转置就行,水过。(不过用G++好像会编译错误,改C或C++就行)
代码:
#include<stdio.h> #include<string.h> int main() { char str1[1001],str2[1001]; int s,i,len; scanf("%d",&s); getchar(); while(s--) { scanf("%s",str1); strcpy(str2,str1); strrev(str1);//**倒置字符串**// if(strcmp(str1,str2)==0) { printf("yes\n"); } else printf("no\n"); } return 0; }
本文提供了一种简洁的方法来解决回文判断问题,通过使用strrev函数进行字符串反转,并比较反转前后是否一致来快速判断输入字符串是否为回文。
236

被折叠的 条评论
为什么被折叠?



