[PAT] A1019 General Palindromic Number
【题目】
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的更多相关文章
- 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 ...
- PAT A1019 General Palindromic Number (20 分)
AC代码 #include <cstdio> const int max_n = 1000; long long ans[max_n]; int num = 0; void change( ...
- PAT 1019 General Palindromic Number
1019 General Palindromic Number (20 分) A number that will be the same when it is written forwards ...
- PAT 1019 General Palindromic Number[简单]
1019 General Palindromic Number (20)(20 分) A number that will be the same when it is written forward ...
- 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 ...
- A1019. General Palindromic Number
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642
PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642 题目描述: A number that will ...
- PAT 甲级 1019 General Palindromic Number(20)(测试点分析)
1019 General Palindromic Number(20 分) A number that will be the same when it is written forwards or ...
- PAT 甲级 1019 General Palindromic Number(简单题)
1019. General Palindromic Number (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN ...
随机推荐
- 使用 Visual Studio 2015 + Python3.6 + tensorflow 构建神经网络时报错:'utf-8' codec can't decode byte 0xcc in position 78: invalid continuation byte
使用 Visual Studio 2015 + Python3.6 + tensorflow 构建神经网络时报错:'utf-8' codec can't decode byte 0xcc in pos ...
- 20200105--python学习数据类型总结
总结 python中的数据类型:整型/布尔类型/字符串/元组/列表/字典/集合 注意:列表,字典,集合都不能作为字典中的key,也不能作为集合中的元素 数据类型: (1)整型 (2)布尔类型:只有两个 ...
- 排查 Kubernetes HPA 通过 Prometheus 获取不到 http_requests 指标的问题
部署好了 kube-prometheus 与 k8s-prometheus-adapter (详见之前的博文 k8s 安装 prometheus 过程记录),使用下面的配置文件部署 HPA(Horiz ...
- 访问控制列表 ACL
访问控制列表(Access Control List,ACL) 是路由器和交换机接口的指令列表,用来控制端口进出的数据包.其目的是为了对某种访问进行控制. 作用 ACL可以限制网络流量.提高网络性能. ...
- 简单ts文件结构
一.ts文件结构 DEMO{ 1. .vscode:特有文件夹,调试的配置文件,启动浏览器 2. Js:放ts编译后的文件,不管 3. Ts:放ts文件,敲代码 4. tsconfig.json:ts ...
- centos7.5下yum安装php-5.6.40(LNMP环境)
cd /etc/yum.repos.d/ yum -y install epel-release #<===安装centos7下php5.6的epel和remi源 rpm -ivh http:/ ...
- [Redis-CentOS7]Redis打开远程连接(十) Could not connect to Redis at 127.0.0.1:6379: Connection refused
通过网络无法访问Redis redis-cli 172.16.1.111 Could not connect to Redis at 127.0.0.1:6379: Connection refuse ...
- [Python]判断变量类型是否为List列表
用法:isinstance(变量,list) li = [1,2,3] print(type(li)) if isinstance(li,list): print("This is a Li ...
- C# 小游戏-拼图魔方【Game Puzzle】
工作闲暇之余去逛了逛CodeProject,刚好现有项目主要用到就是winform,浏览了下照片,找到上周带着蛋挞打疫苗回家的照片,于是新生一记,如何把这些图片玩起来~ 80后应该都有印象,小时候有种 ...
- redis教程-redis环境搭建安装(qq:1324981084)
需要整套redis缓存高可用集群教学视频的加qq:1324981084,本套视频从安装到集群的搭建和源码的解析,从零基础讲解. 1.利用命令将redis下载到/usr/local/文件夹下: wget ...