zoukankan      html  css  js  c++  java
  • 回文指的是一个字符串从前面读和从后面读都一 样,编写一个算法判断一个字符串是否为回文。

    回文指的是一个字符串从前面读和从后面读都一

       样,编写一个算法判断一个字符串是否为回文。

       要求:

              1)采用链栈实现算法;

              2)从键盘输入一个字符串,输出判断结果。

    #include"stdio.h"
    #include"stdlib.h"
    typedef char ElemType;
    typedef struct stnode
    {
        ElemType data;
        struct stnode *next;
    }StNode, *LinkStack;
    int huiwen(char str[])
    {
        int i = 0;
        char ch;
        StNode *sl = NULL, *p;
        while ((ch = str[i++]) != '\0')
        {
            p = (StNode *)malloc(sizeof(StNode));
            p->data = ch;
            p->next = sl;
            sl = p;
        }
        i = 0;
        while (sl != NULL)
        {
            p = sl;
            ch = p->data;
            sl = sl->next;
            free(p);
            if (ch != str[i++])
                return 0;
        }
        return 1;
    }
    void main()
    {
        char string[20];
        int hw;
        printf("input a string:");
        gets_s(string);
        hw = huiwen(string);
        if (hw) printf("The string is HUIWEN.");
        else printf("The string is not HUIWEN.");
    }

    欢迎访问我的博客https://www.ndmiao.cn/

  • 相关阅读:
    Slf4j框架的用法
    常用框架介绍
    Spring整合Kafka(Spring-Kafka)
    Java并发容器
    kafka多线程消费
    kafka简介
    kafka-clients介绍
    windows搭建kafka
    rocketmq-client使用
    Window搭建部署RocketMQ
  • 原文地址:https://www.cnblogs.com/ndmiao/p/10657639.html
Copyright © 2011-2022 走看看