总时间限制:1000ms 内存限制: 65536kB

描述

给出一系列非负整数,判断是否是一个回文数。回文数指的是正着写和倒着写相等的数。

输入

一行,一个01字符串。

输出

若干行,每行是一个非负整数(不超过99999999)

样例输入

11

123

0

14277241

67945497

样例输出

YES

NO

YES

YES

NO


ps.这个题是若干行输入...

题目链接

ac代码

/*
@File : palidrome.cpp
@Time : 2020/03/25 09:47:24
@Desc : 回文数字(Palindrome Number)
*/
#include <iostream>
#include <stdlib.h>
#include <string.h>
#define MAX_LEN 20 using namespace std;
//栈
typedef struct
{
char data[MAX_LEN];
int top;
}Stack;
//初始化
void InitStack(Stack *&stack);
//压栈
bool Push(Stack *&stack, const char num);
//弹栈
bool Pop(Stack *&stack);
//栈是否为空
bool Empty(const Stack *stack);
//获取栈顶
bool get_top(const Stack *stack, char &top);
//判断非负整数是否为回文数
bool JudgePalindrome(const string num);
int main(int argc, char const *argv[])
{
char num[MAX_LEN];
while (gets(num)) //直接cin一个数据不能过
{ //别问我为啥
if (JudgePalindrome(num)) cout << "YES\n"; //
else cout << "NO\n";
}
system("pause");
return 0;
}
void InitStack(Stack *&stack)
{
stack = (Stack*)malloc(sizeof(Stack));
stack->top = -1;
}
bool Push(Stack *&stack, const char num)
{
if (stack->top == MAX_LEN - 1) return false;
stack->top++;
stack->data[stack->top] = num;
return true;
}
bool Pop(Stack *&stack)
{
if (Empty(stack)) return false;
stack->top--;
return true;
}
bool Empty(const Stack *stack)
{
return (stack->top == -1);
}
bool get_top(const Stack *stack, char &top)
{
if (Empty(stack)) return false;
top = stack->data[stack->top];
return true;
}
bool JudgePalindrome(const string num)
{
Stack *stack;
char top = 'n';
int mid = num.size()/2 - 1;
InitStack(stack);
for (int i = 0; i <= mid; i++) Push(stack,num[i]);
if (num.size()%2 == 0) {
for (int i = mid + 1; i < num.size(); i++) {
get_top(stack,top);
if (top == num[i]) Pop(stack);
}
} else {
for (int i = mid + 2; i < num.size(); i++) {
get_top(stack,top);
if (top == num[i]) Pop(stack);
}
}
return Empty(stack);
}

回文数字(Palindrome Number)的更多相关文章

  1. [Swift]LeetCode9. 回文数 | Palindrome Number

    Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same back ...

  2. Leetcode 9 回文数Palindrome Number

    判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 示例 1: 输入: 121 输出: true 示例 2: 输入: -121 输出: false 解释: 从左向 ...

  3. 《LeetBook》leetcode题解(9):Palindrome Number[E]——回文数字

    我现在在做一个叫<leetbook>的开源书项目,把解题思路都同步更新到github上了,需要的同学可以去看看 地址:https://github.com/hk029/leetcode 这 ...

  4. LeetCode 9. Palindrome Number (回文数字)

    Determine whether an integer is a palindrome. Do this without extra space. 题目标签:Math 题目给了我们一个int x, ...

  5. [LeetCode] Palindrome Number 验证回文数字

    Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. S ...

  6. [LeetCode] 9. Palindrome Number 验证回文数字

    Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same back ...

  7. LeetCode 9 Palindrome Number(回文数字判断)

    Long Time No See !   题目链接https://leetcode.com/problems/palindrome-number/?tab=Description   首先确定该数字的 ...

  8. javascript 实现一个回文数字

    写一个方法,让"1234"变成回文数字“1234321”,就是顺着读和倒着读都是一样的:注:不让用reverse()方法: function palindrome(str){ va ...

  9. [2014亚马逊amazon] 在线笔试题 大于非负整数N的第一个回文数 Symmetric Number

    1.题目 如标题,求大于整数N(N>=0)的第一个回文数的字符串表示形式. 这个题目也是当时笔试第一次见到,花了一个小时才做出了.慢慢总结还是挺简单的. 2.分析 分析如下: (1)一位数N(9 ...

随机推荐

  1. 这行代码告诉你!为什么你地下城与勇士(DNF)的装备强化老是失败?

    模拟地下城与勇士(DNF)的装备强化 tip1: DNF装备强化在+1-+3 不会失败: +4-+7,失败后物品原有强化等级降低1级: +8-+10,失败后掉3级: 10上11或以上就爆了. tip2 ...

  2. 使用 Docker 部署 Spring Boot 项目,带劲!!

    上一篇:年轻人的第一个 Docker 应用 Docker 一次构建.处处运行及快速启停的特性,在微服务架构中有着举足轻重的地位,具体的概念性的东西就不介绍了,不懂的点击这里阅读 Docker 基础教程 ...

  3. Mac系统应该用什么软件进行清理?

    作为一枚资深的Windows系统使用者,小编刚刚转向Mac系统的怀抱时,各种不适应,Windows系统中普遍使用的360清理软件目前暂时没有Mac版本的,这就让小编很是头疼了,大家的Mac都是用的什么 ...

  4. guitar pro系列教程(二):Guitar Pro主界面之记谱功能的详细解析【下】

    本章节我们接着上一章节继续讲解关于guitar pro主界面的记谱功能里的符号功能.有兴趣的朋友可以进来一起学习哦. 首先我们看下图,这是点击按钮便会弹出的一个窗口,进入这个窗口,我们会看到" ...

  5. 再论<? extends T>和<? super T>

    参考: https://www.cnblogs.com/drizzlewithwind/p/6100164.html Java 泛型 <? super T> 中 super 怎么 理解?与 ...

  6. C++基础知识篇:C++ 基本语法

    C++ 基本语法 C++ 程序可以定义为对象的集合,这些对象通过调用彼此的方法进行交互.现在让我们简要地看一下什么是类.对象,方法.即时变量. 对象 - 对象具有状态和行为.例如:一只狗的状态 - 颜 ...

  7. Pycharm永久激活方法

    1.下载新版破解补丁 链接 https://pan.baidu.com/s/137-afPKYfkXbvroSv1hoYw 提取码: cm43  下载补丁文件jetbrains-agent.jar并将 ...

  8. fist-第六天冲刺随笔

    这个作业属于哪个课程 https://edu.cnblogs.com/campus/fzzcxy/2018SE1 这个作业要求在哪里 https://edu.cnblogs.com/campus/fz ...

  9. iNeuOS工业互联平台,WEB组态(iNeuView)图元和数据点组合及生成新图元复用,实现拖业务

    目       录 1.      概述... 1 2.      平台演示... 2 3.      应用过程... 2 1.   概述 iNeuView视图建模Web组态平台实现图元和数据点组合及 ...

  10. 老猿学5G扫盲贴:移动边缘计算(Mobile Edge Computing, MEC)

    版权声明:本文为CSDN博主「魏晓蕾」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明. 原文链接:https://blog.csdn.net/gongxifaca ...