妙趣横生算法 4:判断字符串是否回文
2012-01-23 23:23
323 查看
实例说明
“回文”是指顺读和反读内容均相同的字符串,例如,“121”,“ABBA”等。
实例解析
引入两个指针变量,开始时,两指针分别指向字符串的首末字符,当两指针所指字符相等时,两指针分别向后和向前移一个字符位置,并继续比较,直至两指针相遇,说明该字符是回文。若比较过程中,发现两字符不相等,则可以判断该字符串不是回文!
程序代码
#include <stdio.h> #define MAX 50 int cycle(char *s) { char *h,*t; for(h=s,t=s+strlen(s)-1;t>h;h++,t--) { if(*h!=*t) { break; } } return t<=h; } main() { char s[MAX]; while(1) { printf("Please input the string you want to judge(input ^ to quit):"); scanf("%s",s); if(s[0]=='^') { break; } if(cycle(s)) { printf("%s is a cycle string.\n",s); } else { printf("%s is not a cycle string.\n",s); } } printf("\n Thank you for your using,bye bye!\n"); }
个人总结
。。。。新年快乐!继续努力!
相关文章推荐
- 使用栈判断给定字符串是否是回文的算法
- 算法基础——判断一个字符串至多添加一个字符之后是否回文
- 设计一个算法判断一个字符串是否是回文
- 数据结构——算法之(005)(判断字符串是否是对称的即(回文字符串))
- 每天一道算法题1 判断字符串是否是回文字符串或者是否含有回文字符子串
- 算法:判断字符串是否是回文的
- 简单递归____判断一个字符串是否为回文
- C语言OJ项目参考(2802)判断字符串是否为回文
- 判断一个字符串(超过80个字符)是否是回文结构(正序和逆序相同)
- 从零开始学习算法(Java实现)~~~~之字符串篇~~~判断两个字符串是否是颠倒字母顺序构成的
- Problem C: 判断字符串是否为回文
- 判断一个字符串是否为回文
- C语言小算法集锦---判断输入的数字是否为回文数
- 判断字符串是否是回文字符串或者是否含有回文字符子串
- 算法:判断一个字符串是否包含另一个字符串
- C++实现判断字符串是否回文实例解析
- 判断一个字符串是否为回文,以及求一个字符串中最长回文串
- 判断一个字符串是否为回文(递归)
- 编程判断字符串是否为回文 判断一个字符串是否是回文,例如单词‘level’
- 问题 C: 判断字符串是否为回文