c语言三个字符回文序列,写一个算法,判别读入的一个以@为结束符的字符序列是否是“回文”...

满意答案

02ae427d08e371d7e90d5b995e828d6d.png

siawrn

2013.07.01

02ae427d08e371d7e90d5b995e828d6d.png

采纳率:41%    等级:11

已帮助:6495人

#include

#define INIT_SIZE 20

#define INCR_SIZE 10

unsigned int StrLen(char *str)/// 求出字符串中含有的字符个数,不包括结束标志

{/// * 这里我没有用库函数求长度,我不知道怎么用

unsigned int i;

for (i=0; str[i++]!='\0';);

return (i - 1);

}

int IsPalindrome(char * str)

{

int len = StrLen(str);

int i = 0;

for (;i

if (str[i] != str[len-i-1]) return 0;

}

return 1;

}

void main()

{

char * str = (char *) malloc (INIT_SIZE * sizeof(char));

char ch;

int i = 0;//字符串当前字符数

int len = INIT_SIZE;//字符串空间大小

while (ch = getchar()) {// 循环录入字符串

if (ch == '@') {///如果按回车键,则结束

str[i] = '\0';///字符串结束标志

break;

}

if (i < len-1) {

str[i] = ch;

} else {

str = (char *) realloc (str, (len + INCR_SIZE) * sizeof(char)); //增加存储空间

str[i] = ch;

len += INCR_SIZE;//重新记录字符串空间

}

i++;

}

if (IsPalindrome(str) != 0) {

printf("YES\n");

} else {

printf("NO\n");

}

}

00分享举报

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值