总时间限制: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. 在linux系统中通过fw_printenv查看和设置u-boot中的环境变量

    uboot下可以通过命令访问(printenv)和修改环境变量(setenv),但是如果需要在Linux系统下访问这些数据该怎么办呢?其实uboot早就帮我们想好了.  1.编译fw_printenv ...

  2. 细说FL Studio中的Wasp合成器功能

    FL Studio 简称FL,因其Logo像水果,故国人亲切的叫他"水果"本章节采用图文结合的方式给大家讲解FL Studio中的Wasp合成器功能.感兴趣的朋友可以一起来交流哦. ...

  3. FL studio系列教程(十五):FL Studio文件菜单功能详讲

    在FL Studio主控面板上的是其主菜单.主菜单包括:文件.编辑.添加.样式.查看.选项.工具和帮助.如下图所示: 为了帮助初学者快速的了解并能使用它制作出作品,今天小编将详细地为大家讲解下这些菜单 ...

  4. leetcode 1046

    class Solution {       public int lastStoneWeight(int[] stones) {        MaxHeap s=new MaxHeap(stone ...

  5. appium元素定位总结

    appium元素定位方法总结 使用uiautomator定位 driver.find_element_by_android_uiautomator(uia_string) 根据resourceId属性 ...

  6. 蓝桥杯-RP大冒险-未解决

    RP大冒险 问题描述 请尽情使用各种各样的函数来测试你的RP吧~~~ 输入格式 一个数N表示测点编号. 输出格式 一个0~9的数. 样例输入 0 样例输出 X {当且仅当输出仅有一个数X且X为0~9的 ...

  7. mysql一条sql语句如何执行的?

    mysql 一条sql语句如何执行的? 文章内容源自:极客时间-林晓彬老师-MySQL实战45讲 学习整理 在了解一条查询语句如何执行之前,需要了解下MySQL的基本架构是怎样的,如下图所示: 可以看 ...

  8. kafka入门之broker-水印和leader epoch

    每个kafka副本对象都持有2个重要的属性:日志末端位移LEO,高水印HW Kafka对leader副本和follower副本的LEO更新机制是不同的,后面我们会详细讨论. Kafka对leader副 ...

  9. zk下的kafka节点

    zk从某种程度上说是kafka的单点失效组件. /brokers:里面保存了Kafk集群的所有信息,包括每台broker的注册信息,集群上所有topic的信息等. /controller:保存了Kaf ...

  10. HTML的基本术语

    一.HTML含义1.根据W3C定义,HTML全称Hyper Text Markup Language: 超文本标记语言,用于定义文档的内容结构,该语言书写的代码通常会被浏览器解析执行.二.css含义1 ...