【题目】

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. Go语言实现:【剑指offer】数组中重复的数字

    该题目来源于牛客网<剑指offer>专题. 在一个长度为n的数组里的所有数字都在0到n-1的范围内.数组中某些数字是重复的,但不知道有几个数字是重复的.也不知道每个数字重复几次.请找出数组 ...

  2. Linux相关知识笔记

    Quagga要在linux下编译并配置运行,所有,学习一点linux的基础知识. 安装的Ubuntu,用户名linux,密码1 使能Ubuntu的IP转发功能,需要修改etc/sysctl.conf和 ...

  3. docker device or resource busy

    docker-compose -f docker-compose.yml up -d  时候报错 device or resource busy 使用 docker-compose down 会导致一 ...

  4. [Python]List 过滤

    获取数据库列表屏蔽系统自带数据库 # 原代码 db_list_result = [('master', ), ('tempdb', ), ('model', ), ('msdb', ), ('stud ...

  5. Idea生成代码段

    使用快捷键(ctrl+alt+s)找到:从idea的菜单File->Settings->Editor->Live Templates 先添加Template Group,然后添加Li ...

  6. 北京智和信通IT运维管理系统二次开发服务提供商

    随着云计算.大数据.物联网.移动互联网.人工智能.5G等高新技术的快速发展,数据中心及网络基础设施呈现出井喷式的增长模式,对设备商来说,多.快.好.省的实现定制化网络管理开发,可极大的扩充设备适用范围 ...

  7. Nginx 核心配置

    nginx的核心配置在conf/nginx.conf中. 全局配置块 user root; #运行worker进程的账户,user   用户   [组],默认以nobody账户运行 worker_pr ...

  8. 随着页面滚动,数字自动增大的jquery特效

    首先为了截出gif图,我下载了一个小工具 GifCam: https://www.appinn.com/gifcam/ 随着页面滚动,数字自动增大的jquery特效 主要就是依赖这个脚本script. ...

  9. SAP 如何看某个TR是否传入了Q或者P系统?

    SAP 如何看某个TR是否传入了Q或者P系统? 两种方式可以查询. 1)进入Q系统或者P系统.SE16,看表TPALOG, 输入请求号码, 执行,看记录里的字段TPSTAT_KEY是否为空,如果不为空 ...

  10. Python入门1.0

    第一阶段 基础到高级 ATM+购物车项目 选课系统 计算机病毒 病毒程序(windows)防止被杀死 控制键盘摄像头 上传对方数据 有很强的伪装性 服务端(阿里云) 第二阶段 商业项目 博客系统 路飞 ...