判断回文字符
2010-07-11 16:26
127 查看
//用指针判断回文字符的程序:
# include <stdio.h>
# include <stdlib.h>
# include <string.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];
system("cls");
while(1)
{ puts("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);
}
getch();
}
# include <stdio.h>
# include <stdlib.h>
# include <string.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];
system("cls");
while(1)
{ puts("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);
}
getch();
}
相关文章推荐
- python判断是否可以只插一个字符,让字符串变成回文,返回true/false
- 判断字符序列是否为回文
- 输入一个字符串,判断该字符串插入一个字符,能否使其成为回文字符串
- 判断一个字符串(超过80个字符)是否是回文结构(正序和逆序相同)
- 输入一个英文单词,判断该单词是否是回文,要求用字符数组实现
- 实验九 指针3 、编程判断输入的一串字符是否为“回文
- 判断字符是否为回文
- 参考别人编写的判断回文字符
- 华为机试题:回文字符判断
- 十五周—判断 字符回文
- 程序员面试题精选(37):判断字符串是否是回文字符串或者是否含有回文字符子串
- 判断字符串是否可以通过交换相邻字符得到回文字符串,如果可以输出最少交换次数
- 判断给定的一串字符是否为“回文”。所谓“回文”是指顺读和倒读都一样的字符串。
- 写一个少于 80 字符的函数,判断一个字符串是不是回文字符串
- 【leetcode】对撞指针应用之回文字符串判断(忽略大小写,以及出数字外其他字符)
- 判断一个字符串是否能够通过添加一个字符变成回文序列的方法
- 编写判断一个字符序列是否为回文。回文是指一个字符序列以中间 字符为基准两边字符完全相同,即顺着看和倒着看是相同的字符序列。
- 判断回文字符(包含去空格)
- 每天一道算法题1 判断字符串是否是回文字符串或者是否含有回文字符子串
- 判断字符回文