⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 新建 文本文档 (4).txt

📁 回文是指正向读和反向读都一样的一段数字或者文字,如321123或“able was I ere I saw elba”。编写程序,输入一个9位整数,并判断它是否是回文
💻 TXT
字号:
用栈的
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -