1019. General Palindromic Number (20)

时间限制
400 ms

内存限制
65536 kB

代码长度限制
16000 B

判题程序
Standard

作者
CHEN, Yue

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
#include<stdio.h>
int m[100000];
int main(){int a,b,i=0,j,k;scanf("%d %d",&a,&b);do{                  //转换进制典型方法要牢记 m[i++]=a%b;a/=b;}while(a!=0);for(j=0,k=i-1;j<=k;j++,k--){   //典型方法应牢记 if(m[j]!=m[k]){printf("No\n");break;}}if(j>k){printf("Yes\n");}for(j=i-1;j>0;j--){      //解决pat中常出现的不要结尾空格的方法 printf("%d ",m[j]);}printf("%d",m[j]);return 0;
} 

浙大PAT甲级1019. General Palindromic Number (20)相关推荐

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

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

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

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

  3. 1019. General Palindromic Number (20)

    题目连接:https://www.patest.cn/contests/pat-a-practise/101 原题如下: A number that will be the same when it ...

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

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

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

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

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

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

  7. 浙大PAT甲级1027. Colors in Mars (20)

    1027. Colors in Mars (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue People ...

  8. 1019 General Palindromic Number

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

  9. 18年春季第一题 PAT甲级 1144 The Missing Number (20分) 上限感很重要

    Given N integers, you are supposed to find the smallest positive integer that is NOT in the given li ...

最新文章

  1. 真香!3个月0基础转型大厂数据分析师,他做对了什么?
  2. Nginx 之父被拘留,时隔15年后,前老板提起了版权侵权诉讼!
  3. 回归分析结果表格怎么填_手把手教绘制回归分析结果的森林图GraphPad Prism和Excel...
  4. 机器学习的练功方式(六)——朴素贝叶斯
  5. python中opencv是什么_python-opencv的用法
  6. 算法复习第六章第七章
  7. Hibernate 原汁原味的四种抓取策略(转)
  8. ad 4层板设计实例文件_独家数据 | 1619Fall美研传媒类专业1590+申请实例(含大众传播、新闻学、公共关系、新媒体、整合营销等)...
  9. 织梦dedecms响应式抖音培训课程新闻资讯类网站模板(自适应手机移动端)
  10. c语言程序设计21点扑克牌,C语言程序设计-21点扑克牌游戏.pdf
  11. 《可复制的领导力》读书笔记
  12. 叶子的离开,是风的追逐,还是树的不留恋?
  13. java speech sdk_Microsoft Speech SDK开发包 使用
  14. 秒懂设计模式之组合模式(Composite Pattern)
  15. java.lang.IllegalArgumentException: bound must be positive
  16. MySql安装配置(msi版)
  17. 今年五一北京到三亚的机票1万多??用Python扒一扒三亚都有啥子好玩嘛!!
  18. Android开发中蓝湖(设计稿软件)的使用
  19. IOS开发之App之间的拉起和跳转
  20. 诗经 - 小雅 - 皇皇者华

热门文章

  1. 场景欺诈的策略梳理、总结与实操
  2. Axure智慧、智能乡镇通数字管理服务平台+基础数据管理+招商后台管理+web端高保真管理后台
  3. 当array_filter函数的callback留空时 他会过滤掉所有键值为false的键
  4. UVA - 1267 Network
  5. 子类既要实现接口又要继承抽象类的一个demo
  6. ERROR 1045 (28000): Access denied for user 'username'@'localhost' (using password: YES)
  7. 微软首席技术官:不清楚平板是否昙花一现
  8. 玩转Android---事件监听篇---第2篇
  9. 【转】无法打开登录所请求的数据库 xxxx。登录失败。 用户 'xxxxx' 登录失败。...
  10. git基本操作:上传代码