总时间限制: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. 如何用ABBYY FineReader提取图片中的文字

    作为OCR文字识别软件中的佼佼者,可能大家对于ABBYY FineReader的使用还不熟练,没关系,今天小编就为大家演示,如何用ABBYY FineReader这款文字识别软件,将一张截图中的文字识 ...

  2. ABBYY FineReader 15 PDF文档编辑功能详解

    ABBYY FineReader 15(Windows系统)OCR文字识别软件作为一款通用 PDF 工具,能轻松有效地对各种 PDF文档和纸质文档,进行数字化.检索.编辑.转换.包含.分享和合作,而其 ...

  3. Java8常用的内置函数式接口(一)Predicate、Consumer、Supplier、Function

    Java8常用的内置函数式接口(一) 简介 JDK 1.8 API中包含了很多内置的函数式接口.有些是在以前版本的Java中大家耳熟能详的,例如Comparator接口,或者Runnable接口.对这 ...

  4. Jsoup获取网页内容(并且解决中文乱码问题)

    1. 根据连接地址获取网页内容,解决中文乱码页面内容,请求失败后尝试3次 private static Document getPageContent(String urlStr) { for (in ...

  5. 5w 字 | 172 图 | 超级赛亚级 Spring Cloud 实战

    一.PassJava 项目简介 PassJava-Learning 项目是 PassJava(佳必过)项目的学习教程.对架构.业务.技术要点进行讲解. PassJava 是一款 Java 面试刷题 的 ...

  6. python3错误AttributeError: 'TestSequenceFunctions' object has no attribute 'seq'

    对比了两段代码发现,原来是setUp要用用大写才能被正确引用. 修改后,代码运行成功.

  7. 获取Win和Linux系统启动时间,类似uptime功能,用于判断是否修改过系统时间

    目录 前言 测试代码 Win测试 Linux测试 总结 前言 有时候需要判断系统是否有修改过时间,最简单的方法就是获取当前时间A,然后sleep X秒,然后获取 时间B,如果 时间B - 时间A ≠ ...

  8. 「刷题笔记」LCA问题相关

    板子 ll lg[40]; ll dep[N],fa[N][40]; ll dis[N]; void dfs(ll u,ll f) { dep[u]=dep[f]+1; fa[u][0]=f; for ...

  9. 安装seafile记录文档

    安装yum-cron.iptables .关闭selinux yum -y install cronie yum -y install yum-cron systemctl start yu,-cro ...

  10. 网络拓扑实例09:VRRP组网下同网段内配置基于全局地址池的DHCP服务器

    组网图形 DHCP服务器简介 见前面DHCP服务器文章,不再赘述. 组网需求 如图1所示,某企业内的一台主机通过Switch双归属到SwitchA和SwitchB,SwitchA为主设备,作为DHCP ...