[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 ...
随机推荐
- java设计模式7——桥接模式
java设计模式7--桥接模式 1.桥接模式介绍 桥接模式是将抽象部分与它的实现部分分离,使他们都可以独立的变化.它是一种对象结构型模式,又称为柄体模式或接口模式. 2.解决问题 2.1.将复杂的组合 ...
- coroutine - yield from
yield from yield from x 表达式对 x 对象所做的第一件事是,调用 iter(x),从中获取迭代器.因 此, x 可以是任何可迭代的对象. 可是,如果 yield from 结构 ...
- axios中qs的使用
首先qs是一个npm仓库所管理的包,可通过npm install qs命令进行安装. 地址: https://www.npmjs.com/package/qs qs.parse().qs.string ...
- 浅析word2vec(一)
1 word2vec 在自然语言处理的大部分任务中,需要将大量文本数据传入计算机中,用以信息发掘以便后续工作.但是目前计算机所能处理的只能是数值,无法直接分析文本,因此,将原有的文本数据转换为数值数据 ...
- .NET CORE(C#) WPF简单菜单MVVM绑定
微信公众号:Dotnet9,网站:Dotnet9,问题或建议:请网站留言, 如果对您有所帮助:欢迎赞赏. .NET CORE(C#) WPF简单菜单MVVM绑定 阅读导航 本文背景 代码实现 本文参考 ...
- SQL查询结果自定义排序
一般情况之下,我们可以使用ORDER BY ...ASC或DESC来做查询排序.如: SELECT * FROM [dbo].[SalesPerformance] ORDER BY [Salesman ...
- java循环语句 总结笔记
1.for 循环语句 语法:for(initialization;condition;iteration) public class A { public static void main(Strin ...
- HTML块级、行级元素,特殊字符,嵌套规则
如果介绍HTML网页基本标签的嵌套规则,首先要说的就是元素的分类.元素可以划分为块级元素和行级元素,块级元素是什么?它可以独占一行,可以设置宽高度,默认是100%:行级元素与之相反,它的内容决定它的宽 ...
- idea websorm 激活码(2020-1-6 实测可用)最新
2019年1月6日用 ZSI6IiIsImFzc2lnbmVlRW1haWwiOiIiLCJsaWNlbnNlUmVzdHJpY3Rpb24iOiIiLCJjaGVja0NvbmN1cnJlbnR ...
- 把shp文件处理成Android可以识别中文的版本
针对ArcGIS10.2版本的解决办法(默认中文编码为OEM): 假设现在有一个shp图层文件“图层.shp”,在ArcGIS10.2中可以正常打开,属性表中有中文内容,以此为例进行设置 1.拷贝一个 ...