【题目】

https://pintia.cn/problem-sets/994805342720868352/problems/994805487143337984

题目大意:给定一个N和b,求N在b进制下,是否是一个回文数(Palindromic number)。其中,0<N, b<=10 ^ 9

【思路】

将n转为b进制下的数字,存储到vector<int>中,判断数组两端元素是否全部相等即可。可以倒序存储,不影响回文数的判断。

int最大约为2.14 * 10 ^ 9,不必担心int越界。

【坑】

b进制下的数字可能大于10,不能用字符串存储。用字符的话,数字+'0'可能会超出ascii表示的范围,测试点4过不了。

【代码】

 #include<iostream>
#include<vector>
using namespace std;
int main()
{
int num, base;
cin >> num >> base;
vector<int>output;
while (num)
{
output.push_back(num % base);
num = num / base;
}
bool pal = true;
for (int i = ; i < output.size()/; i++)
{
if (output[i] != output[output.size() - i - ])
{
pal = false;
break;
}
}
if (pal) cout << "Yes" << endl;
else cout << "No" << endl;
for (int i = output.size() - ; i >= ; i--)
{
cout << output[i];
if (i > )cout << " ";
}
return ;
}

[PAT] A1019 General Palindromic Number的更多相关文章

  1. PAT A1019 General Palindromic Number (20 分)——回文,进制转换

    A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...

  2. PAT A1019 General Palindromic Number (20 分)

    AC代码 #include <cstdio> const int max_n = 1000; long long ans[max_n]; int num = 0; void change( ...

  3. PAT 1019 General Palindromic Number

    1019 General Palindromic Number (20 分)   A number that will be the same when it is written forwards ...

  4. PAT 1019 General Palindromic Number[简单]

    1019 General Palindromic Number (20)(20 分) A number that will be the same when it is written forward ...

  5. PAT甲级——A1019 General Palindromic Number

    A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...

  6. A1019. General Palindromic Number

    A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...

  7. PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642 题目描述: A number that will ...

  8. PAT 甲级 1019 General Palindromic Number(20)(测试点分析)

    1019 General Palindromic Number(20 分) A number that will be the same when it is written forwards or ...

  9. PAT 甲级 1019 General Palindromic Number(简单题)

    1019. General Palindromic Number (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN ...

随机推荐

  1. T1飞跃树林 && 【最长等差子序列】

    solution by Mr.gtf 一道简单的递推 首先我们对树高从大到小排序 很容易得到递推式 ans[i]=Σans[j] (j<i && h[j]-h[i]<=K) ...

  2. 一个基于图的数据管理系统-gStore

    gStore是遵循 BSD协议的一个开源项目.一个基于图的 RDF 三元组存储的数据管理系统.该项目是北京大学.滑铁卢大学.香港科技大学的联合研究项目.中国北京大学计算机科学与技术研究所的数据库组对该 ...

  3. lwip eth插拔网线自动维护接口状态

    硬件连线就是将dp83848的INT脚连到STM32的某个中断脚上,这里是PB14 PB14的中断处理函数中,会释放一个信号量,这里只是发生链路状态改变中断(网线插上或拔下) void EXTI15_ ...

  4. LVS 介绍 原理

    一. LVS简介       LVS是Linux Virtual Server的简称,也就是Linux虚拟服务器, 是一个由章文嵩博士发起的自由软件项目,它的官方站点是www.linuxvirtual ...

  5. 线段树学习----C语言

    /* 线段树学习:如果一个节点为i,那么他的左孩子为2I+1,右孩子为2i+2: */ #include<stdio.h> #define min(a,b) a<b?a:b; ]; ...

  6. Vue生命周期和钩子函数及使用keeplive缓存页面不重新加载

    Vue生命周期 每个Vue实例在被创建之前都要经过一系列的初始化过程,这个过程就是vue的生命周期,在这个过程中会有一些钩子函数会得到回调 Vue中能够被网页直接使用的最小单位就是组件,我们经常写的: ...

  7. 优秀 .NET 开源项目集锦

    Github 地址: https://github.com/jasonhua95/awesome-dotnet-core awesome-dotnet-core .NET Core框架.库和软件的中文 ...

  8. 配置 Apache James 邮件服务器以使用加密邮件通讯协议

    可先参照: 使用 Apache James 3.3.0(开源免费) 搭建内网电子邮件服务器(基于 Windows + Amazon Corretto 8)https://www.cnblogs.com ...

  9. You (oracle) are not allowed to use this program (crontab)

      检查一台ORACLE数据库服务器的crontab作业(用户为oracle,实际环境中可能为oracle.也有可能是其它用户)时,发现出现下面提示信息: $ crontab -l You (orac ...

  10. 非常简洁简单的tcp socket库 XKSocket

    一个非常简洁简单的异步tcp socket库,主要就是分包的问题,处理组包,粘包等问题 非常适合新手:) 项目中带有使用示例. http://git.oschina.net/dreamzgj/XKSo ...