回文数判定

给定一个字符串,判定是否是回文数,如abcba是回文数,abc不是


实例输入

abcba


实例输出

abcba是一个回文数


代码:


/*

本实验完成验证一个字符串是否为回文字符串

*/

#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include<math.h>
#define max 10
int top = 100;

void init_stack(char s[])
{
	top = 1;
}

int notempty(char s[])
{
	if(top <= 1){
		return 0;
	}else return 1;
}

void push(char s[],char c)
{
	s[top] = c;
	top ++;
}

char pop(char s[])
{
	if(notempty(s)){
		top = top - 1;
		return s[top];
	}
}
int main()
{
    char s[max];
    gets(s);
    int lenth = strlen(s);
    //printf("%d",lenth);
    char a[top];
    init_stack(a);
    int i;
    for(i = 0; i<lenth/2;i++){
	push(a,s[i]);
    }

    int l = (lenth+1)/2,cnt = 1;
    char temp;
    while(notempty(a)){
	temp = pop(a);
	//printf("%c",temp);
	if(temp == s[l]){
		l ++;
		continue;
	}else{
		cnt = 0;
		break;
	}
	break;
    }

    if(cnt == 0){
	printf("%s不是一个回文字符串",s);
    }else{
	printf("%s是一个回文字符串",s);
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值