1019 General Palindromic Number (20 分)

时间:2021-11-06 21:31:53
1019 General Palindromic Number (20 分)

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 a​i​​ as ∑​i=0​k​​(a​i​​b​i​​). Here, as usual, 0≤a​i​​<b for all i and a​k​​ is non-zero. Then N is palindromic if and only if a​i​​=a​k−i​​ for all i. Zero is written 0 in any base and is also palindromic by definition.

Given any positive 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 positive numbers N and b, where 0<N≤10​9​​ is the decimal number and 2≤b≤10​9​​ 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 "a​k​​ a​k−1​​ ... a​0​​". 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

水题:进制转换,判断是否回文

 /**
 * Copyright(c)
 * All rights reserved.
 * Author : Mered1th
 * Date : 2019-02-24-01.08.29
 * Description : A1019
 */
 #include<cstdio>
 #include<cstring>
 #include<iostream>
 #include<cmath>
 #include<algorithm>
 #include<string>
 #include<unordered_set>
 #include<map>
 #include<vector>
 #include<set>
 using namespace std;
 ;
 bool judge(int s[],int len){
     ;i<len;i++){
         ]){
             return false;
         }
     }
     return true;
 }
 int main(){
 #ifdef ONLINE_JUDGE
 #else
     freopen("1.txt", "r", stdin);
 #endif
     int a,n;
     scanf("%d%d",&a,&n);
     ,s[maxn]={};
     do{
         s[num++]=a%n;
         a/=n;
     }while(a);
     if(judge(s,num)){
         printf("Yes\n");
     }
     else{
         printf("No\n");
     }
     ;i>=;i--){
         printf("%d",s[i]);
         ) printf(" ");
     }
     ;
 }

1019 General Palindromic Number (20 分)的更多相关文章

  1. PAT &lpar;Advanced Level&rpar; Practice 1019 General Palindromic Number &lpar;20 分&rpar; 凌宸1642

    PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642 题目描述: A number that will ...

  2. PAT Advanced 1019 General Palindromic Number &lpar;20 分&rpar;

    A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...

  3. PAT &lpar;Advanced Level&rpar; Practice 1019 General Palindromic Number &lpar;20 分&rpar; (进制转换,回文数)

    A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...

  4. 1019 General Palindromic Number &lpar;20 分&rpar;

    A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...

  5. 【PAT甲级】1019 General Palindromic Number &lpar;20 分&rpar;

    题意: 输入两个正整数n和b(n<=1e9,2<=b<=1e9),分别表示数字的大小和进制大小,求在b进制下n是否是一个回文串,输出“Yes”or“No”,并将数字n在b进制下打印出 ...

  6. 1019 General Palindromic Number &lpar;20&rpar;(20 point&lpar;s&rpar;)

    problem A number that will be the same when it is written forwards or backwards is known as a Palind ...

  7. 1019&period; General Palindromic Number &lpar;20&rpar;

    生词以及在文中意思 forward 向前地 backward 向后地 palindromic 回文的 base 基数(如十进制的10 和二进制的2) numeral system 数制 decimal ...

  8. PAT &lpar;Advanced Level&rpar; 1019&period; General Palindromic Number &lpar;20&rpar;

    简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm&gt ...

  9. PAT甲题题解-1019&period; General Palindromic Number &lpar;20&rpar;-又是水题一枚

    n转化为b进制的格式,问你该格式是否为回文数字(即正着写和倒着写一样)输出Yes或者No并且输出该格式又是水题... #include <iostream> #include <cs ...

  10. PAT A1019 General Palindromic Number &lpar;20 分&rpar;

    AC代码 #include <cstdio> const int max_n = 1000; long long ans[max_n]; int num = 0; void change( ...

随机推荐

  1. Smart3D系列教程5之 《案例实战演练2——大区域的地形三维重建》

    一.前言 Wish3D出品的Smart3D系列教程中,前面一讲说明了小物件的照片三维重建,相信大家对建模的流程有了一定的了解.这次讲解中,我们将演示说明以一组无人机倾斜摄影照片为原始数据,通过Smar ...

  2. PeerConnection

    Example(摘) /*When two peers decide they are going to set up a connection to each other, they both go ...

  3. nylg 小M的因子和

    小M的因子和 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 小M在上课时有些得意忘形,老师想出道题目难住他.小M听说是求因子和,还是非常得意,但是看完题目是求A的B ...

  4. How to delete the icons of Win7 desktop shortcuts

    1. Copy the following bat code in txt type file, 2. save it as file extension type bat, run it as ad ...

  5. ListView学习小结

    ListView小结 ListView 是Android UI中十分重要的一个组件,在数据的显示上能有着十分灵活的表现,其使用也比较简单,一般包括以下几个要点: 1.  可以通过编写ListActiv ...

  6. JDBC&lowbar;获取插入记录的主键值

    <span style="font-size:24px;">package src.com.JDBC2DAO.java; import static org.junit ...

  7. 消息队列-ActiveMQ

    1 业务需求描述 举例描述: 再警情通报的业务时通过发送消息界面可以选择 警情联络,和船情通报两种消息 发送方式可分为 一对一发送:部门对部门.个人对个人 一对多发送:部门对多部门.个人对多人 2 功 ...

  8. python入门(10)使用List和tuple

    python入门(10)使用List和tuple list Python内置的一种数据类型是列表:list.list是一种有序的集合,可以随时添加和删除其中的元素. 比如,列出班里所有同学的名字,就可 ...

  9. 转角遇见——Software

    第一部分:结缘计算机 从五岁开始读书,懵懵懂懂,从小就听长辈们说一定要考一个好大学,高三老师们就更是说:“过了高考,人生就无忧了”.于是似乎,高考就好像是我自出生以来这么多年的唯一愿景.高考成绩下来后 ...

  10. jenkins使用Publish Over SSH中遇到的问题

    在jenkins中想使用publish over ssh来在构建后发送XML或PNG文件至服务器,以便做其它的操作,安装完publish over ssh后,填加构建,发现在构建失败时,不传送文件,老 ...