蓝桥杯求解回文数(栈求解版本)

堆栈构造输出方法求解

问题描述

1221是一个非常特殊的数,它从左边读和从右边读是一样的,编程求所有这样的四位十进制数。

输出格式

按从小到大的顺序输出满足条件的四位十进制数。

python 复制代码
class Stack:
    def __init__(self):
        self.item = []

    def push(self, item):
        self.item.append(item)

    def pop(self):
        return self.item.pop()

    def peak(self):
        return self.item[self.size()-1]

    def size(self):
        return len(self.item)

    def isEmpty(self):
        return self.item == []

class FindPalindrome:
    def __init__(self):
        self.stack = Stack()

    def outputPalindrome(self):
        for i in range(10, 100):
            outNumber = str(i)
            for char in str(outNumber):
                self.stack.push(char)
            while not self.stack.isEmpty():
                outNumber = outNumber + self.stack.pop()
            print(outNumber)


fp = FindPalindrome()
fp.outputPalindrome()
相关推荐
敏编程29 分钟前
一天一个Python库:tomlkit - 轻松解析和操作TOML配置
python
2401_8796938735 分钟前
使用Python进行图像识别:CNN卷积神经网络实战
jvm·数据库·python
yunyun3212341 分钟前
机器学习模型部署:将模型转化为Web API
jvm·数据库·python
团子和二花1 小时前
openclaw平替之nanobot源码解析(七):Gateway与多渠道集成
python·gateway·agent·智能体·openclaw·nanobot
未知鱼1 小时前
Python安全开发之简易目录扫描器(含详细注释)
开发语言·python·安全
Be1k01 小时前
推荐一款语雀知识库批量导出工具
python·gui·工具·语雀·批量导出·原创
重庆小透明1 小时前
【搞定面试之mysql】第一篇:mysql的优化和索引
mysql·面试·职场和发展
Sunshine for you2 小时前
如何用FastAPI构建高性能的现代API
jvm·数据库·python
阿贵---2 小时前
Python Web爬虫入门:使用Requests和BeautifulSoup
jvm·数据库·python
Red丶哞3 小时前
内网自建Postfix使用Python发送邮件
开发语言·python