题目连接:https://www.patest.cn/contests/pat-a-practise/101

原题如下:

A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers.

Although palindromic numbers are most often considered in the decimal system, the concept of palindromicity can be applied to the natural numbers in any numeral system. Consider a number N > 0 in base b >= 2, where it is written in standard notation with k+1 digits ai as the sum of (aibi) for i from 0 to k. Here, as usual, 0 <= ai < b for all i and ak is non-zero. Then N is palindromic if and only if ai = ak-i for all i. Zero is written 0 in any base and is also palindromic by definition.

Given any non-negative decimal integer N and a base b, you are supposed to tell if N is a palindromic number in base b.

Input Specification:

Each input file contains one test case. Each case consists of two non-negative numbers N and b, where 0 <= N <= 109 is the decimal number and 2 <= b <= 109 is the base. The numbers are separated by a space.

Output Specification:

For each test case, first print in one line "Yes" if N is a palindromic number in base b, or "No" if not. Then in the next line, print N as the number in base b in the form "ak ak-1 ... a0". Notice that there must be no extra space at the end of output.

Sample Input 1:

27 2

Sample Output 1:

Yes
1 1 0 1 1

Sample Input 2:

121 5

Sample Output 2:

No
4 4 1这道题应该属于简单题了……一开始我还担心数会很大,得用数组,后来发现int足矣……就是将十进制数转换为任意进制,然后判断是否为回文数。注意下0的情况即可。
 1 #include<stdio.h>
 2 #define MAXN 1005
 3 int main()
 4 {
 5      unsigned int N,b,n;
 6      scanf("%u%u",&N,&b);
 7      unsigned int Traverse[MAXN]={0};
 8     int i=0;
 9     n=N;
10     if (n!=0)
11     {
12     while (N)
13     {
14         Traverse[i++]=N%b;
15         N/=b;
16     }
17     int flag=1;
18     int k;
19     k=--i;
20     for (i=0;i<=k/2;i++)
21     {
22         if (Traverse[i]!=Traverse[k-i])flag=0;
23     }
24
25     if (flag)printf("Yes\n");
26     else printf("No\n");
27     for (i=k;i>=0;i--)
28     {
29         printf("%u",Traverse[i]);
30         if (i!=0)printf(" ");
31     }
32     }
33     else if (n==0)
34     {
35         printf("Yes\n");
36         printf("0");
37     }
38     return 0;
39 }

转载于:https://www.cnblogs.com/wuxiaotianC/p/6361794.html

1019. General Palindromic Number (20)相关推荐

  1. 浙大PAT甲级1019. General Palindromic Number (20)

    1019. General Palindromic Number (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN ...

  2. 1019 General Palindromic Number (20分)_18行代码AC

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 A number that will be the same when it is written forwards or bac ...

  3. 【PAT甲级 BigInteger】1019 General Palindromic Number (20 分) Java版 7/7通过

    题目 一开始只使用了Long,有后面四个测试点过不去,后来换了BigInteger,就通过了. 这题用Java的BigInteger做,可以操作任意长度的数字,感觉有一点取巧了. 如果C或者C++的话 ...

  4. 【PAT甲级 进制转换】1019 General Palindromic Number (20 分) Java版 7/7通过

    题目 这道题可以说是非常友善了,说白了是个水题.题目没什么坑,一次通过,主要思想就是: 输入两个数:num和base 将num按照base进制转换,得到arr 判断arr是否是一个回文数,并且输出这个 ...

  5. PAT甲级1019 General Palindromic Number:[C++题解]进制位、回文数、vector来做

    文章目录 题目分析 题目链接 题目分析 ac代码 #include<bits/stdc++.h> using namespace std;//判回文数 bool check(vector& ...

  6. 1019 General Palindromic Number

    代码如下: 1 #include<iostream> 2 3 using namespace std; 4 int jishu = 0; 5 int stem[50000] = {0}; ...

  7. PAT甲级1024 Palindromic Number:[C++题解]回文串和高精度加法

    文章目录 题目分析 题目链接 题目分析 一个判断是否是回文数的函数:check,思路是使用双指针从两端分别往里走. 另一个是高精度加法函数add,传入两个vector. 另外,vector逆序构造可以 ...

  8. 【题意分析】1024 Palindromic Number (25 分)_38行代码AC

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 A number that will be the same when it is written forwards or bac ...

  9. 【PAT - 甲级1024】Palindromic Number (25分)(大数,模拟)

    题干: A number that will be the same when it is written forwards or backwards is known as a Palindromi ...

最新文章

  1. 获取应用的当前版本号获取当前android系统的版本号
  2. Oracle学习网站
  3. RabbitMQ 官方NET教程(二)【工作队列】
  4. 数据中心机房环境温度与微模块机柜有什么关系?
  5. class.forname().newInstance()
  6. 5G 网络接口与基础流程
  7. android 密码加密
  8. 8.4. su - root
  9. vue 左侧菜单隐藏_vue.js 左侧二级菜单显示与隐藏切换的实例代码?
  10. mysql5.7 单机多实例_MySQL数据库 5.7.21单机多实例安装
  11. JavaScript的作用域(1)
  12. X86栈切换,任务切换
  13. SoapUI安装教程,亲测可用
  14. eclipse插件下载最新地址
  15. SpringBoot Spring Cloud项目学习汇总
  16. 微信隐藏功能:微信怎么群发消息给好友不建群?
  17. 【生活感想】期末考试
  18. 2019中国科大夏令营机试
  19. 2022-2028全球及中国食品加工机械行业研究及十四五规划分析报告
  20. 如何將人臉變漂亮(三)

热门文章

  1. matlab头模型图像,用Matlab解《2013年数据建模比赛》图像碎片拼接题
  2. java if 并列_Java 并列if语句,一个判断失败后,后面的if就不执行了,为什么啊?...
  3. 联系——让世界动起来
  4. html用ajax做三级联动,怎样使用JS+AJAX做出三级联动
  5. javascript继承的原理
  6. GDAL库调试(包括跨语言调试)
  7. 远程服务器传数据库,怎样把本机的mysql数据库上传到远程主机上
  8. c语言贪吃蛇源代码window32,Win32贪吃蛇源代码。背景非常简单
  9. DevExpress统计图TextPattern说明
  10. Linux 2.6 和安卓一样吗,Linux2.4和Linux2.6设备驱动的一些区别