新建 文本文档 (4).txt

来自「回文是指正向读和反向读都一样的一段数字或者文字,如321123或“able wa」· 文本 代码 · 共 47 行

TXT
47
字号
用栈的
#include "iostream.h"
#include "stdio.h"
#include "process.h"
#define N 100
typedef struct
{
    char *base;
    char *top;
}Stack;
void main()
{
    Stack s;
    char str[N];
    int  i = 0;
    if(!(s.base = new char[N]))
    {
        cout<<"Malloc false....."<<endl;
        exit(1);
    }
    s.top=s.base;
    while(1)
    {
        str[i]=getchar();
        if(str[i] == 10)
            break;
        else
        {
            *s.top++ = str[i];
            i++;
        }
    }
    i=0;
    while(s.top != s.base)
    {
        cout<<*--s.top;
        if(*s.top != str[i++])
        {
            cout<<endl<<"it is not a palindrome"<<endl;
            break;
        }
    }
    if(s.top == s.base)
        cout<<endl<<"it is a palindrome"<<endl;
}
 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?