总时间限制: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. 实在是秒啊,我还从来没见过把Spring之AOP讲的这么通俗易懂的,安排!

    Spring之AOP 什么是AOP? AOP 为 Aspect Oriented Programming 的缩写,意思为面向切面编程,是通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术. ...

  2. FL Studio时间面板讲解

    今天我们一起来学习一下FL Studio时间面板的知识.看到这个名词我们一定就会想到该功能跟时间是脱不了关系的,是的,它就是用来显示时间的.它显示当前时间的方法不是很单一,而是有好几个,具体有哪几个下 ...

  3. FL studio系列教程(十二):FL Studio中如何导出音频

    在FL Studio中制作好音乐后,最后展现给我们的是一般的音频文件,我们可以通过FL Studio的文件菜单导出最终的文件格式.下面我们就来详细的看一下FL Studio中是如何导出我们想要的音频格 ...

  4. cocoslua3.17 android机器上播放音效不全

    开发过程中遇到一个问题,一个8秒的音效,在android机器上播放不完就结束了:网上说是由于android播放音效的内存限制的:原因知道了,那怎么解决呢? 通过各种搜索查找发现还是解决不了问题,然后自 ...

  5. DIV滚动条设置添加 CSS滚动条显示与滚动条隐藏

    <!DOCTYPE html> <html> <head> <meta charset="gb2312" /> <title& ...

  6. Win10定期执行python程序

    一:windows10自带的计划程序 第一步:在 计算器右击 --> 选择管理 进入如下界面: 第二步:选择 系统工具 -->  任务计划程序 ,点击右侧的  "创建基本任务&q ...

  7. Java命令行启动jar包更改默认端口以及配置文件的几种方式

    Java命令行启动jar包更改默认端口以及配置文件的几种方式 java -jar xxx.jar --server.port=8081 默认如果jar包没有启动文件,可以采用这种方式进行启动 java ...

  8. dubbo起停之服务暴露

    由上一节可知带上dubbo@Service注解的对象,在注册成为bean之后会进一步注册一个ServiceBean,服务暴露便是在这里 public void afterPropertiesSet() ...

  9. 在HTML中调用打开摄像头

    1 <img src="imgs/qr.png" alt=""> 2 <video src=""></vide ...

  10. MinIO

    MinIO 是一个非常轻量的基于 Apache License v2.0 开源协议的对象存储服务.它兼容亚马逊 S3 云存储服务接口,非常适合于存储大容量非结构化的数据,例如图片.视频.日志文件.备份 ...