博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
leetcode Palindrome Number
阅读量:7029 次
发布时间:2019-06-28

本文共 744 字,大约阅读时间需要 2 分钟。

负数被设定为不是回文数

1 #include
2 3 using namespace std; 4 5 int F(int t) 6 { 7 int f = 1; 8 for (int i = 0; i < t; i++) 9 f = f * 10;10 return f;11 }12 13 bool isPalindrome(int x) 14 {15 int m = x;16 int L = 0;17 while (m > 0)18 {19 m = m / 10;20 L++;21 }22 int n = L / 2;23 while (n>0)24 {25 int m = F(L - 1);26 int c = x / m;27 int t = x % 10;28 if (t != c)29 {30 return false;31 }32 x = x % m;33 x = x / 10;34 L = L - 2;35 n--;36 }37 return true;38 }39 40 int main()41 {42 cout << isPalindrome(2321);43 }

 

转载于:https://www.cnblogs.com/chaiwentao/p/4369997.html

你可能感兴趣的文章
SCP,SSH应用
查看>>
The first day to learn Englisht
查看>>
第二章 单表查询 T-SQL语言基础(1)
查看>>
C#中给RichTextBox加上背景图片
查看>>
竞赛准备篇---(四)子集生成
查看>>
JQuery判断复选框是否有选中
查看>>
ng之{{value}}顺序
查看>>
MSSQL 调用 .net 代码
查看>>
设计模式系列——单例模式 享元模式
查看>>
Web.xml详解(转)
查看>>
二分查找系列
查看>>
The Clocks
查看>>
Face++接口封装
查看>>
ScrewTurn Wiki各种问题解决方法.
查看>>
idea编译时JDK版本变化
查看>>
free命令详解
查看>>
MongoDB整理笔记のCapped Collection
查看>>
Codeforces Round #165 (Div. 2) B - Multithreading
查看>>
修正 FreeBSD 字体锯齿问题
查看>>
刚刚搬家,感觉这里还有些不熟悉,为什么cppblog的登录不了呢?郁闷
查看>>