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 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 N2a(int*,int,int);
int isPalindromic(int *,int); int main()
{
int N,b;
int a[];
while(scanf("%d%d",&N,&b) != EOF){
int len = N2a(a,N,b);
int flag = isPalindromic(a,len);
if(flag)
printf("Yes\n");
else
printf("No\n");
int i;
if(len>)
printf("%d",a[len-]);
for(i=len-;i>=;--i){
printf(" %d",a[i]);
}
printf("\n");
}
return ;
} int N2a(int *a,int N,int base)
{
int i = ;
if(N < )
return -;
else if(N == ){
a[] = ;
return ;
}
while(N){
a[i++] = N % base;
N /= base;
}
return i;
} int isPalindromic(int *a,int len)
{
int i = ,n = len / ;
while(i < n){
if(a[i] != a[len - - i]){
return ;
}
++i;
}
return ;
}

PAT 1019的更多相关文章

  1. PAT 1019 General Palindromic Number

    1019 General Palindromic Number (20 分)   A number that will be the same when it is written forwards ...

  2. PAT 1019 General Palindromic Number[简单]

    1019 General Palindromic Number (20)(20 分) A number that will be the same when it is written forward ...

  3. PAT——1019. 数字黑洞

    给定任一个各位数字不完全相同的4位正整数,如果我们先把4个数字按非递增排序,再按非递减排序,然后用第1个数字减第2个数字,将得到一个新的数字.一直重复这样做,我们很快会停在有“数字黑洞”之称的6174 ...

  4. PAT 1019. 数字黑洞 (20)

    给定任一个各位数字不完全相同的4位正整数,如果我们先把4个数字按非递增排序,再按非递减排序,然后用第1个数字减第2个数字,将得到一个新的数字.一直重复这样做,我们很快会停在有"数字黑洞&qu ...

  5. PAT 1019 数字黑洞

    https://pintia.cn/problem-sets/994805260223102976/problems/994805302786899968 给定任一个各位数字不完全相同的4位正整数,如 ...

  6. PAT 乙级 1019

    题目 题目地址:PAT 乙级 1019 思路 本题没有考虑到小于1000的情况,当小于1000的时需要给vector的向量中推入0,直到向量中有四位数字,之后再进行排序并进行相关计算 代码 #incl ...

  7. PAT(B) 1019 数字黑洞(Java)

    题目链接:1019 数字黑洞 (20 point(s)) 分析 输入正整数n后,将n转成int型数组nArr[4] 用Arrays.sort(int[] a)方法将数组nArr非递减排序 很显然,非递 ...

  8. PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642

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

  9. PAT乙级 1019. 数字黑洞 (20)

    1019. 数字黑洞 (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 给定任一个各位数字不完全相同的4位 ...

随机推荐

  1. Blogilo:Ubuntu下“wlw”

    原文首发:http://www.ido321.com/1274.html 这一篇博客是在Ubuntu的博客客户端blogilo下发布的,感觉有点高大上,特此发布一篇博文记录一下.      博客发布在 ...

  2. Vim小知识

    在退出vim编辑的时候,强制退出是q! 感叹号在前,即!q,表示执行外部shell命令,感叹号在后,即q!,表示强制执行vi命令.

  3. Tkinter教程之Event篇(3)

    本文转载自:http://blog.csdn.net/jcodeer/article/details/1823550 '''Tkinter教程之Event篇(3)''''''11.两个事件同时绑定到一 ...

  4. Tkinter教程之Text(1)篇

    本文转载自:http://blog.csdn.net/jcodeer/article/details/1811343 '''Tkinter教程之Text篇(1)''''''1.创建第一个Text''' ...

  5. Unbutu网卡驱动安装(Intel内置网卡8086:15b8)

    工作中需要在新的实验平台上安装unbuntu14.04操作系统,系统安装好之后发现无法连接网络,分析后是由于缺少网卡驱动的原因. 下面把分析问题的过程及安装网卡驱动步骤介绍如下: 查看PCI信息 su ...

  6. work_8

    1.把程序编译通过, 跑起来. 读懂程序,在你觉得比较难懂的地方加上一些注释,这样大家就能比较容易地了解这些程序在干什么. 把正确的 playPrev(GoMove) 的方法给实现了. 如果大家不会下 ...

  7. JavaScript快排与原生sort的测试

    今天工作室断网!果断回宿舍,不然各种资料都没有.(他说将来会找到!)不好意思,又哼起来了.进入主题,大家都知道,快排是各种排序算法中,最高效的也是应用最广的,还有更重要的一点,面试特别爱考的! 其实大 ...

  8. CSS 去掉IE10中type=password中的眼睛图标

    在IE10中,input[type=password],如果我们输入内容后,内容会变成圆点,这与以前一样,但后面多了一个眼睛图标,我们鼠标移过去按下会出现输入内容.有时我们想去掉这功能.IE10允许我 ...

  9. 转载 从Http到Https

    转载自 http://www.cnblogs.com/silin6/p/5928503.html HTTP 当你在浏览器输入一个网址 (例如 http://tasaid.com)的时候,浏览器发起一个 ...

  10. Umbraco中的Examine Search功能讲解

    转载原地址: http://24days.in/umbraco/2013/getting-started-with-examine/ Everytime I read the word Examine ...