【题目】

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过不了。

【代码】

  1. #include<iostream>
  2. #include<vector>
  3. using namespace std;
  4. int main()
  5. {
  6. int num, base;
  7. cin >> num >> base;
  8. vector<int>output;
  9. while (num)
  10. {
  11. output.push_back(num % base);
  12. num = num / base;
  13. }
  14. bool pal = true;
  15. for (int i = ; i < output.size()/; i++)
  16. {
  17. if (output[i] != output[output.size() - i - ])
  18. {
  19. pal = false;
  20. break;
  21. }
  22. }
  23. if (pal) cout << "Yes" << endl;
  24. else cout << "No" << endl;
  25. for (int i = output.size() - ; i >= ; i--)
  26. {
  27. cout << output[i];
  28. if (i > )cout << " ";
  29. }
  30. return ;
  31. }

[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. 7天用Go动手写/从零实现分布式缓存GeeCache

    1 谈谈分布式缓存 第一次请求时将一些耗时操作的结果暂存,以后遇到相同的请求,直接返回暂存的数据.我想这是大部分童鞋对于缓存的理解.在计算机系统中,缓存无处不在,比如我们访问一个网页,网页和引用的 J ...

  2. win10系统下安装JDK1.8及配置环境变量的方法

    本次演示基于windows10操作系统,如果你是linux,请参考:https://www.yn2333.com/archives/linux上安装JDK8 1:下载安装包 地址:https://ww ...

  3. 关于JAVA中源码级注解的编写及使用

    一.注解简介: 1.1.什么是"注解": ​ 在我们编写代码时,一定看到过这样的代码: class Student { private String name; @Override ...

  4. 【JavaScript】进制转换&位运算,了解一下?

    前言 在一般的代码中很少会接触到进制和位运算,但这不代表我们可以不去学习它.作为一位编程人员,这些都是基础知识.如果你没有学过这方面的知识,也不要慌,接下来的知识并不会很难.本文你将会学习到: 进制转 ...

  5. 你还用拼音为变量命名?新人OIer别傻了,教你写出优质代码

    本篇文章适用语言:python,c++,Java.(其实我就是随便bb) 我们在编辑代码的时候,不免拿其他人的代码进行学习,或者将自己的代码拿给别人修改.这个时候,如何让别人快速读懂你的代码,是提升效 ...

  6. java 获取两个时间之前所有的日期

    正序(2017-01-01 ~2019-xxxxx) package com.founder.util; import java.text.SimpleDateFormat; import java. ...

  7. 再次小结windows服务的编写

    2013-03-23 21:05 (分类:计算机程序) 其实很简单 void mian() { //服务的分派表    SERVICE_TABLE_ENTRY DispatchTable[] ={   ...

  8. 向C++之父Bjarne Stroustrup致敬

    2013-04-25 21:30 (分类:社会人生) 非常好的文章 C ++ 的 背 影                                     ——C++之父Bjarne Strou ...

  9. HDU 4994 博弈。

    F - 6 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status ...

  10. Spring有哪些配置方式

    1.XML 配置文件. Bean 所需的依赖项和服务在 XML 格式的配置文件中指定.这些配置文件通常包含许多 bean 定义和特定于应用程序的配置选项.它们通常以 bean 标签开头.例如: < ...