【题目】

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. VFP的13个SPT函数

    Visual FoxPro 中内置了13个以SQL开头的函数,我们把它们称为SPT函数.就是这13个函数完成了Visual FoxPro的所有的SQL Pass Though功能.从功能上看,我们可以 ...

  2. pytorch之 CNN

    # library # standard library import os # third-party library import torch import torch.nn as nn impo ...

  3. lwip 2.0.2 snmp mib ipv6

    1.3.6.1.2.1 - SNMP MIB-2 Submitted by Harald.T.Alvestrand at uninett.no from host aun.uninett.no (12 ...

  4. 修改 ssh 远程连接 时间

           linux使用的是  红帽旗下 centos.         解释两个文件          /etc/ssh/sshd_config     配置ssh服务器端的          ...

  5. [Python]Bytes 和 String转换

    #----string to bytes------ # 方法一:直接复制bytes类型 b'<str>' b = b'Hello World' print(type(b)) print( ...

  6. Python学习小记(4)---class

    1.名称修改机制 大概是会对形如 __parm 的成员修改为 _classname__spam 9.6. Private Variables “Private” instance variables ...

  7. C#设计模式学习笔记:(13)模板方法模式

    本笔记摘抄自:https://www.cnblogs.com/PatrickLiu/p/7837716.html,记录一下学习过程以备后续查用. 一.引言 今天我们要讲行为型设计模式的第一个模式--模 ...

  8. winform重绘控件边框

    首先添加一个用户控件 对于重绘边框有三个需要考虑的东西 1:是否显示边框 2:边框颜色 3:边框宽度 所以定义三个私有变量 /// <summary>/// 是否显示边框/// </ ...

  9. C# 通过反射检查属性是否包含特定字符串

    public static bool StringFilter(this object model,string filterStr) { if (string.IsNullOrEmpty(filte ...

  10. 深入浅出 .NET C# 反射技术

    反射这个词听起来就很牛逼是吧? 嗯的确,反射是比较高级的特性,只有语言基础很扎实的Dev们才应该使用它. 搞点反射,可以提高程序的灵活性.可扩展性.耦合度. 反射这东西,是为了动态地运行时加载,相比于 ...